Passed
Push — 2.2 ( e99f8e...d74efa )
by
unknown
02:23 queued 10s
created
src/PageTypes/BasePage.php 1 patch
Indentation   +158 added lines, -158 removed lines patch added patch discarded remove patch
@@ -31,162 +31,162 @@
 block discarded – undo
31 31
 
32 32
 class BasePage extends SiteTree
33 33
 {
34
-    private static $icon = 'cwp/cwp:images/icons/sitetree_images/page.png';
35
-
36
-    /**
37
-     * Hide this page type from the CMS. hide_ancestor is slightly misnamed, should really be just "hide"
38
-     *
39
-     * {@inheritDoc}
40
-     */
41
-    private static $hide_ancestor = BasePage::class;
42
-
43
-    private static $api_access = [
44
-        'view' => [
45
-            'Locale', 'URLSegment', 'Title', 'MenuTitle', 'Content', 'MetaDescription',
46
-            'ExtraMenu', 'Sort', 'Version', 'ParentID', 'ID'
47
-        ],
48
-        'edit' => [
49
-            'Locale', 'URLSegment', 'Title', 'MenuTitle', 'Content', 'MetaDescription',
50
-            'ExtraMenu', 'Sort', 'Version', 'ParentID', 'ID'
51
-        ],
52
-    ];
53
-
54
-    private static $table_name = 'BasePage';
55
-
56
-    /**
57
-     * @config
58
-     * @var string
59
-     */
60
-    private static $related_pages_title = 'Related pages';
61
-
62
-    private static $many_many = [
63
-        'Terms' => TaxonomyTerm::class,
64
-        'RelatedPagesThrough' => [
65
-            'through' => RelatedPageLink::class,
66
-            'from' => 'BasePage',
67
-            'to' => 'Child',
68
-        ]
69
-    ];
70
-
71
-    private static $owns = [
72
-        'RelatedPagesThrough',
73
-    ];
74
-
75
-    private static $belongs_many_many = [
76
-        'SimilarPages' => BasePage::class
77
-    ];
78
-
79
-    /**
80
-     * @var array
81
-     * @config
82
-     */
83
-    private static $many_many_extraFields = [
84
-        'RelatedPages' => [
85
-            'SortOrder' => 'Int',
86
-        ],
87
-    ];
88
-
89
-    private static $plural_name = 'Base Pages';
90
-
91
-    /**
92
-     * Get the footer holder.
93
-     */
94
-    public function getFooter()
95
-    {
96
-        return FooterHolder::get_one(FooterHolder::class);
97
-    }
98
-
99
-    /**
100
-     * @deprecated 2.2.0:3.0.0 Please use RelatedPagesThrough() instead
101
-     */
102
-    public function RelatedPages()
103
-    {
104
-        return $this->getManyManyComponents('RelatedPagesThrough');
105
-    }
106
-
107
-    public function RelatedPagesTitle()
108
-    {
109
-        return $this->config()->get('related_pages_title');
110
-    }
111
-
112
-    public function getCMSFields()
113
-    {
114
-        $this->beforeUpdateCMSFields(function (FieldList $fields) {
115
-            // Related Pages
116
-            $components = GridFieldConfig_RelationEditor::create();
117
-            $components->removeComponentsByType(GridFieldAddNewButton::class);
118
-            $components->removeComponentsByType(GridFieldEditButton::class);
119
-            $components->removeComponentsByType(GridFieldFilterHeader::class);
120
-            $components->addComponent(new GridFieldOrderableRows('SortOrder'));
121
-
122
-            /** @var GridFieldDataColumns $dataColumns */
123
-            $dataColumns = $components->getComponentByType(GridFieldDataColumns::class);
124
-            $dataColumns->setDisplayFields([
125
-                'Title' => _t(__CLASS__ . '.ColumnTitle', 'Title'),
126
-                'ClassName' => _t(__CLASS__ . '.ColumnPageType', 'Page Type')
127
-            ]);
128
-
129
-            $fields->findOrMakeTab(
130
-                'Root.RelatedPages',
131
-                _t(__CLASS__ . '.RelatedPages', 'Related pages')
132
-            );
133
-            $fields->addFieldToTab(
134
-                'Root.RelatedPages',
135
-                GridField::create(
136
-                    'RelatedPages',
137
-                    _t(__CLASS__ . '.RelatedPages', 'Related pages'),
138
-                    $this->RelatedPagesThrough(),
139
-                    $components
140
-                )
141
-            );
142
-
143
-            // Taxonomies - Unless they have their own 'Tags' field (such as in Blog, etc)
144
-            $hasMany = $this->hasMany();
145
-            $manyMany = $this->manyMany();
146
-            if (!isset($hasMany['Tags']) && !isset($manyMany['Tags'])) {
147
-                $components = GridFieldConfig_RelationEditor::create();
148
-                $components->removeComponentsByType(GridFieldAddNewButton::class);
149
-                $components->removeComponentsByType(GridFieldEditButton::class);
150
-
151
-                /** @var GridFieldAddExistingAutocompleter $autoCompleter */
152
-                $autoCompleter = $components->getComponentByType(GridFieldAddExistingAutocompleter::class);
153
-                $autoCompleter->setResultsFormat('$Name ($TaxonomyName)');
154
-
155
-                /** @var GridFieldDataColumns $dataColumns */
156
-                $dataColumns = $components->getComponentByType(GridFieldDataColumns::class);
157
-                $dataColumns->setDisplayFields([
158
-                    'Name' => _t(__CLASS__ . '.Term', 'Term'),
159
-                    'TaxonomyName' => _t(__CLASS__ . '.Taxonomy', 'Taxonomy')
160
-                ]);
161
-
162
-                $fields->findOrMakeTab('Root.Tags', _t(__CLASS__ . '.TagsTabTitle', 'Tags'));
163
-                $fields->addFieldToTab(
164
-                    'Root.Tags',
165
-                    TreeMultiselectField::create(
166
-                        'Terms',
167
-                        _t(__CLASS__ . '.Terms', 'Terms'),
168
-                        TaxonomyTerm::class
169
-                    )->setDescription(_t(__CLASS__ . '.TermsDescription', 'Click to search for additional terms'))
170
-                );
171
-            }
172
-        });
173
-        return parent::getCMSFields();
174
-    }
175
-
176
-    /**
177
-     * Returns the native language name for the selected locale/language, empty string if Fluent is not available
178
-     *
179
-     * @return string
180
-     */
181
-    public function getSelectedLanguage()
182
-    {
183
-        if (!class_exists(Locale::class) || !$this->hasMethod('Locales')) {
184
-            return '';
185
-        }
186
-
187
-        /** @var ArrayData $information */
188
-        $information = $this->LocaleInformation(FluentState::singleton()->getLocale());
189
-
190
-        return $information->LanguageNative;
191
-    }
34
+	private static $icon = 'cwp/cwp:images/icons/sitetree_images/page.png';
35
+
36
+	/**
37
+	 * Hide this page type from the CMS. hide_ancestor is slightly misnamed, should really be just "hide"
38
+	 *
39
+	 * {@inheritDoc}
40
+	 */
41
+	private static $hide_ancestor = BasePage::class;
42
+
43
+	private static $api_access = [
44
+		'view' => [
45
+			'Locale', 'URLSegment', 'Title', 'MenuTitle', 'Content', 'MetaDescription',
46
+			'ExtraMenu', 'Sort', 'Version', 'ParentID', 'ID'
47
+		],
48
+		'edit' => [
49
+			'Locale', 'URLSegment', 'Title', 'MenuTitle', 'Content', 'MetaDescription',
50
+			'ExtraMenu', 'Sort', 'Version', 'ParentID', 'ID'
51
+		],
52
+	];
53
+
54
+	private static $table_name = 'BasePage';
55
+
56
+	/**
57
+	 * @config
58
+	 * @var string
59
+	 */
60
+	private static $related_pages_title = 'Related pages';
61
+
62
+	private static $many_many = [
63
+		'Terms' => TaxonomyTerm::class,
64
+		'RelatedPagesThrough' => [
65
+			'through' => RelatedPageLink::class,
66
+			'from' => 'BasePage',
67
+			'to' => 'Child',
68
+		]
69
+	];
70
+
71
+	private static $owns = [
72
+		'RelatedPagesThrough',
73
+	];
74
+
75
+	private static $belongs_many_many = [
76
+		'SimilarPages' => BasePage::class
77
+	];
78
+
79
+	/**
80
+	 * @var array
81
+	 * @config
82
+	 */
83
+	private static $many_many_extraFields = [
84
+		'RelatedPages' => [
85
+			'SortOrder' => 'Int',
86
+		],
87
+	];
88
+
89
+	private static $plural_name = 'Base Pages';
90
+
91
+	/**
92
+	 * Get the footer holder.
93
+	 */
94
+	public function getFooter()
95
+	{
96
+		return FooterHolder::get_one(FooterHolder::class);
97
+	}
98
+
99
+	/**
100
+	 * @deprecated 2.2.0:3.0.0 Please use RelatedPagesThrough() instead
101
+	 */
102
+	public function RelatedPages()
103
+	{
104
+		return $this->getManyManyComponents('RelatedPagesThrough');
105
+	}
106
+
107
+	public function RelatedPagesTitle()
108
+	{
109
+		return $this->config()->get('related_pages_title');
110
+	}
111
+
112
+	public function getCMSFields()
113
+	{
114
+		$this->beforeUpdateCMSFields(function (FieldList $fields) {
115
+			// Related Pages
116
+			$components = GridFieldConfig_RelationEditor::create();
117
+			$components->removeComponentsByType(GridFieldAddNewButton::class);
118
+			$components->removeComponentsByType(GridFieldEditButton::class);
119
+			$components->removeComponentsByType(GridFieldFilterHeader::class);
120
+			$components->addComponent(new GridFieldOrderableRows('SortOrder'));
121
+
122
+			/** @var GridFieldDataColumns $dataColumns */
123
+			$dataColumns = $components->getComponentByType(GridFieldDataColumns::class);
124
+			$dataColumns->setDisplayFields([
125
+				'Title' => _t(__CLASS__ . '.ColumnTitle', 'Title'),
126
+				'ClassName' => _t(__CLASS__ . '.ColumnPageType', 'Page Type')
127
+			]);
128
+
129
+			$fields->findOrMakeTab(
130
+				'Root.RelatedPages',
131
+				_t(__CLASS__ . '.RelatedPages', 'Related pages')
132
+			);
133
+			$fields->addFieldToTab(
134
+				'Root.RelatedPages',
135
+				GridField::create(
136
+					'RelatedPages',
137
+					_t(__CLASS__ . '.RelatedPages', 'Related pages'),
138
+					$this->RelatedPagesThrough(),
139
+					$components
140
+				)
141
+			);
142
+
143
+			// Taxonomies - Unless they have their own 'Tags' field (such as in Blog, etc)
144
+			$hasMany = $this->hasMany();
145
+			$manyMany = $this->manyMany();
146
+			if (!isset($hasMany['Tags']) && !isset($manyMany['Tags'])) {
147
+				$components = GridFieldConfig_RelationEditor::create();
148
+				$components->removeComponentsByType(GridFieldAddNewButton::class);
149
+				$components->removeComponentsByType(GridFieldEditButton::class);
150
+
151
+				/** @var GridFieldAddExistingAutocompleter $autoCompleter */
152
+				$autoCompleter = $components->getComponentByType(GridFieldAddExistingAutocompleter::class);
153
+				$autoCompleter->setResultsFormat('$Name ($TaxonomyName)');
154
+
155
+				/** @var GridFieldDataColumns $dataColumns */
156
+				$dataColumns = $components->getComponentByType(GridFieldDataColumns::class);
157
+				$dataColumns->setDisplayFields([
158
+					'Name' => _t(__CLASS__ . '.Term', 'Term'),
159
+					'TaxonomyName' => _t(__CLASS__ . '.Taxonomy', 'Taxonomy')
160
+				]);
161
+
162
+				$fields->findOrMakeTab('Root.Tags', _t(__CLASS__ . '.TagsTabTitle', 'Tags'));
163
+				$fields->addFieldToTab(
164
+					'Root.Tags',
165
+					TreeMultiselectField::create(
166
+						'Terms',
167
+						_t(__CLASS__ . '.Terms', 'Terms'),
168
+						TaxonomyTerm::class
169
+					)->setDescription(_t(__CLASS__ . '.TermsDescription', 'Click to search for additional terms'))
170
+				);
171
+			}
172
+		});
173
+		return parent::getCMSFields();
174
+	}
175
+
176
+	/**
177
+	 * Returns the native language name for the selected locale/language, empty string if Fluent is not available
178
+	 *
179
+	 * @return string
180
+	 */
181
+	public function getSelectedLanguage()
182
+	{
183
+		if (!class_exists(Locale::class) || !$this->hasMethod('Locales')) {
184
+			return '';
185
+		}
186
+
187
+		/** @var ArrayData $information */
188
+		$information = $this->LocaleInformation(FluentState::singleton()->getLocale());
189
+
190
+		return $information->LanguageNative;
191
+	}
192 192
 }
Please login to merge, or discard this patch.