1<?php 2 3 4namespace ComboStrap\Meta\Field; 5 6 7use ComboStrap\ExceptionCompile; 8use ComboStrap\FileSystems; 9use ComboStrap\Meta\Api\Metadata; 10use ComboStrap\Meta\Api\MetadataWikiPath; 11use ComboStrap\WikiPath; 12 13/** 14 * @deprecated 15 */ 16class PageImagePath extends MetadataWikiPath 17{ 18 19 public const PERSISTENT_NAME = "path"; 20 const PROPERTY_NAME = "image-path"; 21 22 23 public static function createFromParent(Metadata $metadata): PageImagePath 24 { 25 return (new PageImagePath($metadata)); 26 } 27 28 29 static public function getDescription(): string 30 { 31 return "The path of the image"; 32 } 33 34 static public function getLabel(): string 35 { 36 return "Path"; 37 } 38 39 static public function getName(): string 40 { 41 return self::PROPERTY_NAME; 42 } 43 44 static public function getPersistentName(): string 45 { 46 return self::PERSISTENT_NAME; 47 } 48 49 50 static public function getPersistenceType(): string 51 { 52 return Metadata::PERSISTENT_METADATA; 53 } 54 55 static public function isMutable(): bool 56 { 57 return true; 58 } 59 60 static public function getFormControlWidth(): int 61 { 62 return 8; 63 } 64 65 66 public function setFromStoreValue($value): Metadata 67 { 68 WikiPath::addRootSeparatorIfNotPresent($value); 69 $path = WikiPath::createMediaPathFromPath($value); 70 if (!FileSystems::exists($path)) { 71 throw new ExceptionCompile("The image ($value) does not exists", $this->getCanonical()); 72 } 73 return parent::setFromStoreValue($value); 74 } 75 76 77 static public function getDrive(): string 78 { 79 return WikiPath::MEDIA_DRIVE; 80 } 81} 82