1<?php
2
3namespace ComboStrap\Meta\Field;
4
5use ComboStrap\ExceptionNotFound;
6use ComboStrap\FirstSvgIllustration;
7use ComboStrap\MarkupPath;
8use ComboStrap\Meta\Api\Metadata;
9use ComboStrap\Meta\Api\MetadataImage;
10use ComboStrap\Meta\Store\MetadataDokuWikiStore;
11use ComboStrap\WikiPath;
12
13
14class FeaturedSvgImage extends MetadataImage
15{
16
17    const PROPERTY_NAME = "featured-svg-image";
18    const ITEM_FEATURED_IMAGE_PARSED = "item-featured-svg-image-parsed";
19
20
21    public static function createFromResourcePage(MarkupPath $markupPath): FeaturedSvgImage
22    {
23        return (new FeaturedSvgImage())->setResource($markupPath);
24    }
25
26    static public function getDescription(): string
27    {
28        return "A featured image in svg format";
29    }
30
31    static public function getLabel(): string
32    {
33        return "Featured Svg Image";
34    }
35
36    public static function getName(): string
37    {
38        return "featured-svg-image";
39    }
40
41    static public function getPersistenceType(): string
42    {
43        return Metadata::PERSISTENT_METADATA;
44    }
45
46    static public function isMutable(): bool
47    {
48        return true;
49    }
50
51
52    public function setParsedValue(string $path = null): FeaturedSvgImage
53    {
54        $store = $this->getWriteStore();
55        if ($store instanceof MetadataDokuWikiStore) {
56            $store->setFromPersistentName(self::ITEM_FEATURED_IMAGE_PARSED, $path);
57        }
58        return $this;
59    }
60
61    public function getDefaultValue(): WikiPath
62    {
63
64        /**
65         * Parsed Feature Images
66         */
67        $parsedValue = $this->getReadStore()->getFromName(self::ITEM_FEATURED_IMAGE_PARSED);
68        if ($parsedValue === null) {
69            throw new ExceptionNotFound();
70        }
71        return WikiPath::createMediaPathFromPath($parsedValue);
72
73    }
74
75
76    static public function getDrive(): string
77    {
78        return WikiPath::MEDIA_DRIVE;
79    }
80
81    static public function isOnForm(): bool
82    {
83        return true;
84    }
85
86    public static function getCanonical(): string
87    {
88        return FeaturedImage::getCanonical();
89    }
90}
91