1<?php
2
3
4namespace ComboStrap;
5
6
7class PageType extends MetadataText
8{
9
10
11    /**
12     * @link https://ogp.me/#types Facebook ogp
13     * @link https://www.dublincore.org/specifications/dublin-core/dcmi-terms/#http://purl.org/dc/elements/1.1/type Dublin Core
14     */
15    public const PROPERTY_NAME = "type";
16    public const BLOG_TYPE = "blog";
17    public const WEB_PAGE_TYPE = "webpage";
18    public const ARTICLE_TYPE = "article";
19    public const ORGANIZATION_TYPE = "organization";
20    public const NEWS_TYPE = "news";
21    public const OTHER_TYPE = "other";
22    public const WEBSITE_TYPE = "website";
23    public const HOME_TYPE = "home";
24    public const EVENT_TYPE = "event";
25    /**
26     * Default page type configuration
27     */
28    public const CONF_DEFAULT_PAGE_TYPE = "defaultPageType";
29    public const CONF_DEFAULT_PAGE_TYPE_DEFAULT = PageType::ARTICLE_TYPE;
30
31    public static function createForPage($page): PageType
32    {
33        return (new PageType())
34            ->setResource($page);
35    }
36
37    public function getTab(): string
38    {
39        return MetaManagerForm::TAB_TYPE_VALUE;
40    }
41
42    public function getDescription(): string
43    {
44        return "The type of page";
45    }
46
47    public function getLabel(): string
48    {
49        return "Page Type";
50    }
51
52    static public function getName(): string
53    {
54        return self::PROPERTY_NAME;
55    }
56
57    public function getPersistenceType(): string
58    {
59        return Metadata::PERSISTENT_METADATA;
60    }
61
62    public function getMutable(): bool
63    {
64        return true;
65    }
66
67    public function getDefaultValue(): ?string
68    {
69        $resource = $this->getResource();
70        if(!($resource instanceof Page)){
71            return null;
72        }
73
74        if ($resource->isRootHomePage()) {
75            return PageType::WEBSITE_TYPE;
76        } else if ($resource->isHomePage()) {
77            return PageType::HOME_TYPE;
78        } else {
79            $defaultPageTypeConf = PluginUtility::getConfValue(PageType::CONF_DEFAULT_PAGE_TYPE, PageType::CONF_DEFAULT_PAGE_TYPE_DEFAULT);
80            if (!empty($defaultPageTypeConf)) {
81                return $defaultPageTypeConf;
82            } else {
83                return null;
84            }
85        }
86    }
87
88    /**
89     * The canonical for page type
90     */
91    public function getCanonical(): string
92    {
93        return "page:type";
94    }
95
96
97    public function getPossibleValues(): ?array
98    {
99        $types = [
100            self::ORGANIZATION_TYPE,
101            self::ARTICLE_TYPE,
102            self::NEWS_TYPE,
103            self::BLOG_TYPE,
104            self::WEBSITE_TYPE,
105            self::EVENT_TYPE,
106            self::HOME_TYPE,
107            self::WEB_PAGE_TYPE,
108            self::OTHER_TYPE
109        ];
110        sort($types);
111        return $types;
112    }
113}
114