1<?php 2 3 4namespace ComboStrap; 5 6 7use ComboStrap\Meta\Api\Metadata; 8use ComboStrap\Meta\Api\MetadataText; 9 10class PageUrlType extends MetadataText 11{ 12 13 public const CONF_CANONICAL_URL_TYPE = "pageUrlType"; 14 public const CONF_CANONICAL_URL_TYPE_DEFAULT = self::CONF_VALUE_PAGE_PATH; 15 public const CONF_VALUE_PAGE_PATH = "page path"; 16 public const CONF_VALUE_SLUG = "slug"; 17 public const CONF_VALUE_CANONICAL_PATH = "canonical path"; 18 public const CONF_VALUE_HIERARCHICAL_SLUG = "hierarchical slug"; 19 public const CONF_VALUE_PERMANENT_PAGE_PATH = "permanent page path"; 20 public const CONF_VALUE_PERMANENT_CANONICAL_PATH = "permanent canonical path"; 21 public const CONF_VALUE_HOMED_SLUG = "homed slug"; 22 public const CONF_VALUES = [ 23 PageUrlType::CONF_VALUE_PAGE_PATH, 24 PageUrlType::CONF_VALUE_PERMANENT_PAGE_PATH, 25 PageUrlType::CONF_VALUE_CANONICAL_PATH, 26 PageUrlType::CONF_VALUE_PERMANENT_CANONICAL_PATH, 27 PageUrlType::CONF_VALUE_SLUG, 28 PageUrlType::CONF_VALUE_HOMED_SLUG, 29 PageUrlType::CONF_VALUE_HIERARCHICAL_SLUG 30 ]; 31 32 33 public static function createFromPage(ResourceCombo $page): PageUrlType 34 { 35 return (new PageUrlType()) 36 ->setResource($page); 37 } 38 39 public function getValue(): string 40 { 41 42 $resourceCombo = $this->getResource(); 43 if (!$resourceCombo->exists()) { 44 return PageUrlType::CONF_VALUE_PAGE_PATH; 45 } 46 if (!($resourceCombo instanceof MarkupPath)) { 47 LogUtility::msg("The page type is only for page"); 48 return PageUrlType::CONF_VALUE_PAGE_PATH; 49 } 50 51 $confCanonicalType = $this->getName(); 52 $confDefaultValue = $this->getDefaultValue(); 53 $urlType = SiteConfig::getConfValue($confCanonicalType, $confDefaultValue); 54 if (!in_array($urlType, self::CONF_VALUES)) { 55 LogUtility::msg("The canonical configuration ($confCanonicalType) value ($urlType) is unknown and was set to the default one", LogUtility::LVL_MSG_ERROR, PageUrlPath::PROPERTY_NAME); 56 return $confDefaultValue; 57 } 58 59 return $urlType; 60 61 62 } 63 64 65 static public function getTab(): string 66 { 67 return MetaManagerForm::TAB_PAGE_VALUE; 68 } 69 70 static public function getDescription(): string 71 { 72 return "The type of Url for pages"; 73 } 74 75 static public function getLabel(): string 76 { 77 return "Page Url"; 78 } 79 80 static public function getName(): string 81 { 82 return PageUrlType::CONF_CANONICAL_URL_TYPE; 83 } 84 85 static public function getPersistenceType(): string 86 { 87 return Metadata::PERSISTENT_METADATA; 88 } 89 90 static public function isMutable(): bool 91 { 92 return true; 93 } 94 95 /** 96 * @return string 97 */ 98 public function getDefaultValue(): string 99 { 100 return PageUrlType::CONF_CANONICAL_URL_TYPE_DEFAULT; 101 } 102} 103