1<?php
2
3namespace ComboStrap;
4
5use ComboStrap\Meta\Api\Metadata;
6use ComboStrap\Meta\Api\MetadataImage;
7use ComboStrap\Meta\Store\MetadataDokuWikiStore;
8
9/**
10 * A derived meta that captures the first svg image
11 * via {@link \syntax_plugin_combo_media::registerFirstImage()}
12 *
13 * Note: The first svg icon is captured at {@link FeaturedIcon::FIRST_ICON_PARSED}
14 */
15class FirstSvgIllustration extends MetadataImage
16{
17
18
19    public const PROPERTY_NAME = "first-svg-illustration";
20
21    public static function createForPage(ResourceCombo $resource): FirstSvgIllustration
22    {
23        return (new FirstSvgIllustration())
24            ->setResource($resource);
25    }
26
27    static public function getDescription(): string
28    {
29        return "The first svg illustration of the page";
30    }
31
32    static public function getLabel(): string
33    {
34        return "First Svg illustration";
35    }
36
37    public static function getName(): string
38    {
39        return self::PROPERTY_NAME;
40    }
41
42
43    static public function isMutable(): bool
44    {
45        return false;
46    }
47
48    public function buildFromReadStore(): FirstSvgIllustration
49    {
50
51        $this->wasBuild = true;
52        $store = $this->getReadStore();
53        if (!($store instanceof MetadataDokuWikiStore)) {
54            return $this;
55        }
56
57        /**
58         * Dokuwiki stores the first image in under relation
59         * but as we can't take over the renderer code to enable svg as first image
60         * we write it in the root to overcome a conflict
61         *
62         * Image set by {@link \syntax_plugin_combo_media::registerFirstImage()}
63         */
64        $firstImageId = $store->getFromName(FirstSvgIllustration::PROPERTY_NAME);
65
66
67        $this->setFromStoreValueWithoutException($firstImageId);
68
69        return $this;
70    }
71
72
73    static public function getPersistenceType(): string
74    {
75        return Metadata::DERIVED_METADATA;
76    }
77
78    static public function getDrive(): string
79    {
80        return WikiPath::MEDIA_DRIVE;
81    }
82}
83