Skip to content
This repository was archived by the owner on Oct 13, 2025. It is now read-only.

Commit fcc129d

Browse files
authored
Add after update cms fields extension point trait
1 parent c0ad983 commit fcc129d

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

code/ExtraPageFieldsExtension.php

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,13 @@ public function updateCMSFields(FieldList $fields)
2828
//Add secondary heading - H2
2929
$fields->insertAfter(TextField::create('SubTitle', 'Secondary Heading'), 'Title');
3030

31-
//Move meta fields to their own tab
31+
if(!in_array('HasOnAfterUpdateCMSFieldsExtensionPoint', class_uses($this->owner))){
32+
$this->afterUpdateCMSFields($fields);
33+
}
34+
}
3235

36+
public function afterUpdateCMSFields(FieldList $fields)
37+
{
3338
/** @var ToggleCompositeField $metaDataChildren */
3439
$metaDataChildren = $fields->fieldByName('Root.Main.Metadata');
3540
// ddd($metaDataChildren->fieldByName('MetaDescription'));
@@ -44,7 +49,6 @@ public function updateCMSFields(FieldList $fields)
4449

4550
$metaTitle->setDescription('Displayed as the tab/window name; Also displayed in search engine result listings as the page title.<br />
4651
Falls back to the Primary Heading field if not provided.');
47-
4852
}
4953

5054
public function updateSettingsFields(FieldList $fields)
@@ -61,10 +65,11 @@ public function updateSettingsFields(FieldList $fields)
6165
return empty($this->owner->MenuTarget) ? '' : "target=\"{$this->owner->MenuTarget}\"";
6266
}
6367

64-
Public function MetaTags(& $tags) {
65-
if(is_a(Director::get_current_page(), 'Security')){
68+
Public function MetaTags(& $tags)
69+
{
70+
if (is_a(Director::get_current_page(), 'Security')) {
6671
$tags = $tags . '<meta name="robots" content="noindex">';
67-
}
72+
}
6873
}
6974

7075
public function onBeforeWrite()
@@ -81,4 +86,17 @@ public function onBeforeWrite()
8186
}
8287
}
8388

89+
trait HasOnAfterUpdateCMSFieldsExtensionPoint
90+
{
91+
public function __construct($record = null, $isSingleton = false, $model = null)
92+
{
93+
parent::__construct($record, $isSingleton, $model);
94+
95+
$this->afterExtending('updateCMSFields', function (FieldList $fields) {
96+
$this->extend('afterUpdateCMSFields', $fields);
97+
});
98+
}
99+
100+
}
101+
84102

0 commit comments

Comments
 (0)