1<?php 2 3 4namespace ComboStrap; 5 6 7class Region extends MetadataText 8{ 9 10 11 public const PROPERTY_NAME = "region"; 12 public const OLD_REGION_PROPERTY = "country"; 13 public const CONF_SITE_LANGUAGE_REGION = "siteLanguageRegion"; 14 15 public static function createForPage(Page $page) 16 { 17 return (new Region()) 18 ->setResource($page); 19 } 20 21 public function getTab(): ?string 22 { 23 return MetaManagerForm::TAB_LANGUAGE_VALUE; 24 } 25 26 /** 27 * @throws ExceptionCombo 28 */ 29 public function setFromStoreValue($value): Metadata 30 { 31 32 $this->validityCheck($value); 33 return parent::setFromStoreValue($value); 34 35 } 36 37 /** 38 * @param string|null $value 39 * @return Metadata 40 * @throws ExceptionCombo 41 */ 42 public function setValue($value): Metadata 43 { 44 $this->validityCheck($value); 45 return parent::setValue($value); 46 } 47 48 49 public function getDescription(): string 50 { 51 return "The region of the language"; 52 } 53 54 public function getLabel(): string 55 { 56 return "Region"; 57 } 58 59 static public function getName(): string 60 { 61 return self::PROPERTY_NAME; 62 } 63 64 public function getPersistenceType(): string 65 { 66 return Metadata::PERSISTENT_METADATA; 67 } 68 69 public function getMutable(): bool 70 { 71 return true; 72 } 73 74 public function getDefaultValue() 75 { 76 return Site::getLanguageRegion(); 77 } 78 79 /** 80 * @throws ExceptionCombo 81 */ 82 private function validityCheck($value) 83 { 84 if ($value === "" || $value === null) { 85 return; 86 } 87 if (!StringUtility::match($value, "^[a-zA-Z]{2}$")) { 88 throw new ExceptionCombo("The region value ($value) for the page ({$this->getResource()}) does not have two letters (ISO 3166 alpha-2 region code)", $this->getCanonical()); 89 } 90 } 91 92 public function getCanonical(): string 93 { 94 return "region"; 95 } 96 97 98} 99