1<?php 2 3 4namespace ComboStrap; 5 6 7class PageKeywords extends MetadataMultiple 8{ 9 10 public const PROPERTY_NAME = "keywords"; 11 12 13 public static function createForPage(Page $page) 14 { 15 return (new PageKeywords()) 16 ->setResource($page); 17 } 18 19 public function getTab(): string 20 { 21 return MetaManagerForm::TAB_PAGE_VALUE; 22 } 23 24 25 public function getDataType(): string 26 { 27 // in a form, we send a list of words 28 return DataType::TEXT_TYPE_VALUE; 29 } 30 31 32 public function getDescription(): string 33 { 34 return "The keywords added to your page (separated by a comma)"; 35 } 36 37 public function getLabel(): string 38 { 39 return "Keywords"; 40 } 41 42 static public function getName(): string 43 { 44 return self::PROPERTY_NAME; 45 } 46 47 48 /** 49 * The default of dokuwiki is the recursive parts of all {@link ResourceName page name} 50 * in the hierarchy. 51 * @return string[]|null 52 */ 53 public function getDefaultValue(): ?array 54 { 55 56 $resource = $this->getResource(); 57 if (!($resource instanceof Page)) { 58 return null; 59 } 60 $keyWords = explode(" ", $resource->getNameOrDefault()); 61 $actualPage = $resource; 62 while (($parentPage = $actualPage->getParentPage()) !== null) { 63 if (!$parentPage->isRootHomePage()) { 64 $parentKeyWords = explode(" ", $parentPage->getNameOrDefault()); 65 $keyWords = array_merge($keyWords, $parentKeyWords); 66 } 67 $actualPage = $parentPage; 68 } 69 $keyWords = array_map(function ($element) { 70 return strtolower($element); 71 }, $keyWords); 72 return array_unique($keyWords); 73 } 74 75 public function getPersistenceType(): string 76 { 77 return Metadata::PERSISTENT_METADATA; 78 } 79 80 public function getMutable(): bool 81 { 82 return true; 83 } 84 85 86 public function buildFromStoreValue($value): Metadata 87 { 88 try { 89 $this->array = $this->toArrayOrNull($value); 90 } catch (ExceptionCombo $e) { 91 LogUtility::msg($e->getMessage(), LogUtility::LVL_MSG_ERROR, $e->getMessage()); 92 } 93 return $this; 94 } 95 96 97 98 public function getCanonical(): string 99 { 100 return self::PROPERTY_NAME; 101 } 102 103 104} 105