1<?php 2 3 4namespace ComboStrap; 5 6 7class Locale extends MetadataText 8{ 9 10 const PROPERTY_NAME = "locale"; 11 12 public static function createForPage(Page $page) 13 { 14 return (new Locale()) 15 ->setResource($page); 16 } 17 18 public function getTab(): string 19 { 20 return MetaManagerForm::TAB_LANGUAGE_VALUE; 21 } 22 23 public function getDescription(): string 24 { 25 return "The locale define the language and the formatting of numbers and time for the page. It's generated from the language and region metadata."; 26 } 27 28 public function getLabel(): string 29 { 30 return "Locale"; 31 } 32 33 public function getValue(): ?string 34 { 35 36 $resourceCombo = $this->getResource(); 37 if (!($resourceCombo instanceof Page)) { 38 return null; 39 } 40 $lang = $resourceCombo->getLangOrDefault(); 41 if (!empty($lang)) { 42 43 $country = $resourceCombo->getRegionOrDefault(); 44 if (empty($country)) { 45 $country = $lang; 46 } 47 return $lang . "_" . strtoupper($country); 48 } 49 return null; 50 } 51 52 53 public static function getName(): string 54 { 55 return self::PROPERTY_NAME; 56 } 57 58 public function getPersistenceType(): string 59 { 60 return Metadata::DERIVED_METADATA; 61 } 62 63 public function getMutable(): bool 64 { 65 return false; 66 } 67 68 public function getDefaultValue(): ?string 69 { 70 /** 71 * The value of {@link locale_get_default()} is with an underscore 72 * We follow this lead 73 */ 74 return Site::getLocale("_"); 75 } 76 77 public function getCanonical(): string 78 { 79 return "locale"; 80 } 81 82 83} 84