1<?php 2 3 4namespace ComboStrap; 5 6 7use ComboStrap\Meta\Api\MetadataText; 8use ComboStrap\Meta\Field\PageH1; 9use ComboStrap\Meta\Store\MetadataDokuWikiStore; 10 11class PageTitle extends MetadataText 12{ 13 14 public const PROPERTY_NAME = 'title'; 15 public const TITLE = 'title'; 16 17 public static function createForMarkup($page): PageTitle 18 { 19 return (new PageTitle()) 20 ->setResource($page); 21 } 22 23 public static function getTab(): string 24 { 25 return MetaManagerForm::TAB_PAGE_VALUE; 26 } 27 28 public static function getDescription(): string 29 { 30 return "The page title is a description advertised to external application such as search engine and browser."; 31 } 32 33 public static function getLabel(): string 34 { 35 return "Title"; 36 } 37 38 static public function getName(): string 39 { 40 return self::PROPERTY_NAME; 41 } 42 43 public static function getPersistenceType(): string 44 { 45 return MetadataDokuWikiStore::PERSISTENT_DOKUWIKI_KEY; 46 } 47 48 public static function isMutable(): bool 49 { 50 return true; 51 } 52 53 /** 54 * `title` is created by DokuWiki 55 * in current but not persistent 56 * and hold the heading 1, see {@link p_get_first_heading} 57 */ 58 public function getDefaultValue(): string 59 { 60 61 $resource = $this->getResource(); 62 if (!($resource instanceof MarkupPath)) { 63 LogUtility::internalError("Resource that are not page have no title"); 64 return ResourceName::getFromPath($resource->getPathObject()); 65 } 66 if ($resource->isRootHomePage() && !empty(Site::getTagLine())) { 67 return Site::getTagLine(); 68 } 69 return PageH1::createForPage($this->getResource()) 70 ->getValueOrDefault(); 71 72 } 73 74 /** 75 * @return string 76 */ 77 public function getValueOrDefault(): string 78 { 79 try { 80 return $this->getValue(); 81 } catch (ExceptionNotFound $e) { 82 return $this->getDefaultValue(); 83 } 84 } 85 86 87 public static function getCanonical(): string 88 { 89 return self::TITLE; 90 } 91 92 93 public static function isOnForm(): bool 94 { 95 return true; 96 } 97 98} 99