Skip to content

Commit

Permalink
Merge pull request #28 from wedevelopnl/fix/fix-fluent-conflict
Browse files Browse the repository at this point in the history
Wrap all field mutations inside `beforeUpdateCMSFields`
  • Loading branch information
erikfrerejean authored Jun 19, 2023
2 parents 959dbb0 + 1efc6ce commit d2893e8
Show file tree
Hide file tree
Showing 5 changed files with 187 additions and 180 deletions.
6 changes: 4 additions & 2 deletions src/ElementalGrid/ElementArticle.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ public function getCMSFields(): FieldList
TreeDropdownField::create(
'ArticlePageID',
_t(__CLASS__ . '.ARTICLETOSHOW', 'Article to show'),
ArticlePage::class),
ArticlePage::class
),
CheckboxField::create(
'ShowMoreArticlesButton',
_t('WeDevelop\Articles\ElementalGrid.SHOWMOREBUTTON', "Show 'more articles' button")
Expand All @@ -90,7 +91,8 @@ public function getCMSFields(): FieldList
TreeDropdownField::create(
'ArticlesPageID',
_t(__CLASS__ . '.ARTICLESPAGE', 'Articles overview page'),
SiteTree::class),
SiteTree::class
),
TextField::create(
'ShowMoreArticlesButtonText',
_t('WeDevelop\Articles\ElementalGrid.SHOWMOREBUTTONTEXT', "Show 'more articles' button text")
Expand Down
68 changes: 34 additions & 34 deletions src/Models/Author.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,42 +80,42 @@ class Author extends DataObject

public function getCMSFields(): FieldList
{
$fields = parent::getCMSFields();

$fields->removeByName(
[
'ArticlesPageID',
'Slug',
'Function',
'Bio',
'Phone',
'Email',
'FacebookURL',
'TwitterURL',
'LinkedInURL',
]
);

$fields->renameField('Title', 'Name');

$fields->addFieldsToTab(
'Root.Main',
[
TextField::create('Function', 'Function'),
UploadField::create('Image', 'Image')->setFolderName('Authors'),
HTMLEditorField::create('Bio', 'Bio')->setRows(5),
HeaderField::create('', 'Contact details'),
TextField::create('Phone', 'Phone'),
TextField::create('Email', 'E-mailaddress'),
HeaderField::create('', 'Social media'),
TextField::create('FacebookURL', 'Facebook URL'),
TextField::create('TwitterURL', 'Twitter URL'),
TextField::create('LinkedInURL', 'LinkedIn URL'),
]
);
$this->beforeUpdateCMSFields(function (FieldList $fields) {
$fields->removeByName(
[
'ArticlesPageID',
'Slug',
'Function',
'Bio',
'Phone',
'Email',
'FacebookURL',
'TwitterURL',
'LinkedInURL',
]
);

$fields->renameField('Title', 'Name');

$fields->addFieldsToTab(
'Root.Main',
[
TextField::create('Function', 'Function'),
UploadField::create('Image', 'Image')->setFolderName('Authors'),
HTMLEditorField::create('Bio', 'Bio')->setRows(5),
HeaderField::create('', 'Contact details'),
TextField::create('Phone', 'Phone'),
TextField::create('Email', 'E-mailaddress'),
HeaderField::create('', 'Social media'),
TextField::create('FacebookURL', 'Facebook URL'),
TextField::create('TwitterURL', 'Twitter URL'),
TextField::create('LinkedInURL', 'LinkedIn URL'),
]
);
});

$this->extend('onAfterUpdateCMSFields', $fields);

return $fields;
return parent::getCMSFields();
}
}
11 changes: 5 additions & 6 deletions src/Models/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,14 @@ class Tag extends DataObject
*/
public function getCMSFields()
{
$fields = parent::getCMSFields();

$fields->removeByName('ArticlesPageID');

$fields->renameField('Title', _t(__CLASS__ . '.NAME', 'Name'));
$this->beforeUpdateCMSFields(function (FieldList $fields) {
$fields->removeByName('ArticlesPageID');
$fields->renameField('Title', _t(__CLASS__ . '.NAME', 'Name'));
});

$this->extend('onAfterUpdateCMSFields', $fields);

return $fields;
return parent::getCMSFields();
}

/**
Expand Down
156 changes: 81 additions & 75 deletions src/Pages/ArticlePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,97 +105,103 @@ class ArticlePage extends \Page

public function getCMSFields(): FieldList
{
$fields = parent::getCMSFields();

$fields->removeByName('MenuTitle');

$fields->insertAfter(
'URLSegment',
TextField::create('Subtitle', _t(__CLASS__ . '.SUBTITLE', 'Subtitle'))
);

$fields->replaceField('Content', HTMLEditorField::create('Content'));

$fields->insertAfter(
'Subtitle',
FieldGroup::create(
[
TextField::create('ReadingTime', _t(__CLASS__ . '.READINGTIME', 'Reading time (in min.)')),
DatetimeField::create('PublicationDate', _t(__CLASS__ . '.PUBLICATIONDATE', 'Publication date')),
DatetimeField::create('UpdatedDate', _t(__CLASS__ . '.UPDATEDATE', 'Update date')),
]
)
$this->beforeUpdateCMSFields(function (FieldList $fields) {
$fields->removeByName('MenuTitle');

$fields->insertAfter(
'URLSegment',
TextField::create('Subtitle', _t(__CLASS__ . '.SUBTITLE', 'Subtitle'))
);

$fields->replaceField('Content', HTMLEditorField::create('Content'));

$fields->insertAfter(
'Subtitle',
FieldGroup::create(
[
TextField::create('ReadingTime', _t(__CLASS__ . '.READINGTIME', 'Reading time (in min.)')),
DatetimeField::create('PublicationDate', _t(__CLASS__ . '.PUBLICATIONDATE', 'Publication date')),
DatetimeField::create('UpdatedDate', _t(__CLASS__ . '.UPDATEDATE', 'Update date')),
]
)
->setName('ArticleMetadata')
->setTitle(_t(__CLASS__ . '.METADATA', 'Metadata'))
);

$fields->insertAfter(
'ArticleMetadata',
TagField::create(
);

$fields->insertAfter(
'ArticleMetadata',
TagField::create(
'Themes',
_t('WeDevelop\Articles\Pages\ArticleThemePage.PLURALNAME', 'Themes'),
ArticleThemePage::get()->filter('ParentID', $this->ParentID),
$this->Themes()
)->setCanCreate(false)
);

$fields->insertAfter(
'Themes',
_t('WeDevelop\Articles\Pages\ArticleThemePage.PLURALNAME', 'Themes'),
ArticleThemePage::get()->filter('ParentID', $this->ParentID),
$this->Themes()
)->setCanCreate(false)
);

$fields->insertAfter(
'Themes',
TagField::create(
TagField::create(
'Tags',
_t('WeDevelop\Articles\Models\Tag.PLURALNAME', 'Tags'),
Tag::get()->filter(
[
'ArticlesPageID' => $this->ParentID,
]
),
$this->Tags()
)
);

$fields->insertAfter(
'Tags',
_t('WeDevelop\Articles\Models\Tag.PLURALNAME', 'Tags'),
Tag::get()->filter(
[
'ArticlesPageID' => $this->ParentID,
]
),
$this->Tags()
)
);

$fields->insertAfter(
'Tags',
DropdownField::create(
'AuthorID',
_t('WeDevelop\Articles\Models\Author.SINGULARNAME', 'Author'),
Author::get()->filter(
[
'ArticlesPageID' => $this->ParentID,
]
DropdownField::create(
'AuthorID',
_t('WeDevelop\Articles\Models\Author.SINGULARNAME', 'Author'),
Author::get()->filter(
[
'ArticlesPageID' => $this->ParentID,
]
)
)
)
->setHasEmptyDefault(true)
);
);

$fields->insertAfter(
'AuthorID',
DropdownField::create(
'TypeID',
_t('WeDevelop\Articles\Pages\ArticleTypePage.SINGULARNAME', 'Type'),
ArticleTypePage::get()->filter(
[
'ParentID' => $this->ParentID,
]
$fields->insertAfter(
'AuthorID',
DropdownField::create(
'TypeID',
_t('WeDevelop\Articles\Pages\ArticleTypePage.SINGULARNAME', 'Type'),
ArticleTypePage::get()->filter(
[
'ParentID' => $this->ParentID,
]
)
)
)
->setHasEmptyDefault(true)
);
);

$fields->insertAfter(
'TypeID',
HTMLEditorField::create('TeaserText', _t(__CLASS__ . '.TEASERTEXT', 'Teaser text'))
$fields->insertAfter(
'TypeID',
HTMLEditorField::create(
'TeaserText',
_t(__CLASS__ . '.TEASERTEXT', 'Teaser text')
)
->setRows(5)
);
);

$fields->insertAfter(
'TeaserText',
UploadField::create('Thumbnail', _t(__CLASS__ . '.THUMBNAIL', 'Thumbnail'))
$fields->insertAfter(
'TeaserText',
UploadField::create(
'Thumbnail',
_t(__CLASS__ . '.THUMBNAIL', 'Thumbnail')
)
->setFolderName('Thumbnails')
);
);
});

$this->extend('onAfterUpdateCMSFields', $fields);

return $fields;
return parent::getCMSFields();
}

public function getControllerName(): string
Expand Down
Loading

0 comments on commit d2893e8

Please sign in to comment.