xref: /plugin/combo/ComboStrap/FeaturedIcon.php (revision 04fd306c7c155fa133ebb3669986875d65988276)
1<?php
2
3namespace ComboStrap;
4
5use ComboStrap\Meta\Api\Metadata;
6use ComboStrap\Meta\Api\MetadataImage;
7
8/**
9 * A derived meta that captures the first raster image
10 * via {@link \syntax_plugin_combo_media::registerFirstImage()}
11 */
12class FeaturedIcon extends MetadataImage
13{
14
15    public const PROPERTY_NAME = "featured-icon";
16    public const FIRST_ICON_PARSED = "first-icon-image-parsed";
17
18    public static function createForPage(ResourceCombo $resource): FeaturedIcon
19    {
20        return (new FeaturedIcon())
21            ->setResource($resource);
22    }
23
24    static public function getDescription(): string
25    {
26        return "An illustrative icon for the page";
27    }
28
29    static public function getLabel(): string
30    {
31        return "Featured Icon";
32    }
33
34    public static function getName(): string
35    {
36        return self::PROPERTY_NAME;
37    }
38
39
40    static public function isMutable(): bool
41    {
42        return true;
43    }
44
45
46    static public function getPersistenceType(): string
47    {
48        return Metadata::PERSISTENT_METADATA;
49    }
50
51    public function getDefaultValue()
52    {
53        /**
54         *
55         * Image set by {@link \syntax_plugin_combo_media::registerFirstImage()}
56         */
57        $iconImageParsed = $this->getReadStore()->getFromName(FeaturedIcon::FIRST_ICON_PARSED);
58
59        if ($iconImageParsed !== null) {
60            return WikiPath::createMediaPathFromId($iconImageParsed);
61        }
62
63        throw new ExceptionNotFound();
64    }
65
66    static public function getDrive(): string
67    {
68        return WikiPath::MEDIA_DRIVE;
69    }
70
71    static public function isOnForm(): bool
72    {
73        return true;
74    }
75}
76