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(): WikiPath 52 { 53 54 /** 55 * @var MarkupPath $page 56 */ 57 $page = $this->getResource(); 58 if($page->isRootHomePage()){ 59 try { 60 return Site::getLogoAsSvgImage(); 61 } catch (ExceptionNotFound $e) { 62 // not found 63 } 64 } 65 66 /** 67 * 68 * Image set by {@link \syntax_plugin_combo_media::registerFirstImage()} 69 */ 70 $iconImageParsed = $this->getReadStore()->getFromName(FeaturedIcon::FIRST_ICON_PARSED); 71 72 if ($iconImageParsed !== null) { 73 return WikiPath::createMediaPathFromId($iconImageParsed); 74 } 75 76 throw new ExceptionNotFound(); 77 } 78 79 static public function getDrive(): string 80 { 81 return WikiPath::MEDIA_DRIVE; 82 } 83 84 static public function isOnForm(): bool 85 { 86 return true; 87 } 88} 89