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