1<?php 2 3namespace ComboStrap\Meta\Field; 4 5use ComboStrap\MarkupPath; 6use ComboStrap\Meta\Api\Metadata; 7use ComboStrap\Meta\Api\MetadataImage; 8use ComboStrap\PageImageUsage; 9use ComboStrap\WikiPath; 10 11 12class TwitterImage extends MetadataImage 13{ 14 15 16 const PROPERTY_NAME = "twitter-image"; 17 18 public static function createFromResource(MarkupPath $page) 19 { 20 return (new TwitterImage())->setResource($page); 21 } 22 23 static public function getDescription(): string 24 { 25 return "The twitter image used in twitter card"; 26 } 27 28 static public function getLabel(): string 29 { 30 return "Twitter Image"; 31 } 32 33 public static function getName(): string 34 { 35 return self::PROPERTY_NAME; 36 } 37 38 static public function getPersistenceType(): string 39 { 40 return Metadata::PERSISTENT_METADATA; 41 } 42 43 static public function isMutable(): bool 44 { 45 return true; 46 } 47 48 public function setFromStoreValueWithoutException($value): Metadata 49 { 50 51 if ($value === null) { 52 $pageImages = PageImages::createForPage($this->getResource()) 53 ->setReadStore($this->getReadStore()) 54 ->getValueAsPageImages(); 55 foreach ($pageImages as $pageImage) { 56 if (in_array(PageImageUsage::TWITTER, $pageImage->getUsages())) { 57 return parent::setFromStoreValueWithoutException($pageImage->getImagePath()->toAbsoluteId()); 58 } 59 } 60 } 61 return parent::setFromStoreValueWithoutException($value); 62 63 } 64 65 public function getDefaultValue() 66 { 67 68 return SocialCardImage::createFromResourcePage($this->getResource()) 69 ->getValueOrDefault(); 70 71 } 72 73 static public function getDrive(): string 74 { 75 return WikiPath::MEDIA_DRIVE; 76 } 77 78 static public function isOnForm(): bool 79 { 80 return true; 81 } 82 83 public static function getCanonical(): string 84 { 85 return "twitter"; 86 } 87 88 89} 90