mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
Merge pull request #2 from catcherdev/master
Wrap getCMSFields in beforeUpdateCMSFields for decorator overrides
This commit is contained in:
commit
f9eb2a76f1
@ -61,8 +61,12 @@ class BlogPost extends Page {
|
|||||||
|
|
||||||
|
|
||||||
public function getCMSFields() {
|
public function getCMSFields() {
|
||||||
$fields = parent::getCMSFields();
|
|
||||||
|
|
||||||
|
// Assign to variable & pass for PHP <= 5.4 closure compatibility
|
||||||
|
$data['TagsMap'] = $this->Parent()->Tags()->map()->toArray();
|
||||||
|
$data['CategoryMap'] = $this->Parent()->Categories()->map()->toArray();
|
||||||
|
|
||||||
|
$this->beforeUpdateCMSFields(function($fields) use ($data) {
|
||||||
// Add Publish date fields
|
// Add Publish date fields
|
||||||
$fields->insertAfter(
|
$fields->insertAfter(
|
||||||
$publishDate = DatetimeField::create("PublishDate", _t("BlogPost.PublishDate", "Publish Date")),
|
$publishDate = DatetimeField::create("PublishDate", _t("BlogPost.PublishDate", "Publish Date")),
|
||||||
@ -71,13 +75,11 @@ class BlogPost extends Page {
|
|||||||
$publishDate->getDateField()->setConfig("showcalendar", true);
|
$publishDate->getDateField()->setConfig("showcalendar", true);
|
||||||
|
|
||||||
// Add Categories & Tags fields
|
// Add Categories & Tags fields
|
||||||
$categories = $this->Parent()->Categories()->map()->toArray();
|
$categoriesField = ListboxField::create("Categories", _t("BlogPost.Categories", "Categories"), $data['CategoryMap'])
|
||||||
$categoriesField = ListboxField::create("Categories", _t("BlogPost.Categories", "Categories"), $categories)
|
|
||||||
->setMultiple(true);
|
->setMultiple(true);
|
||||||
$fields->insertAfter($categoriesField, "PublishDate");
|
$fields->insertAfter($categoriesField, "PublishDate");
|
||||||
|
|
||||||
$tags = $this->Parent()->Tags()->map()->toArray();
|
$tagsField = ListboxField::create("Tags", _t("BlogPost.Tags", "Tags"), $data['TagsMap'])
|
||||||
$tagsField = ListboxField::create("Tags", _t("BlogPost.Tags", "Tags"), $tags)
|
|
||||||
->setMultiple(true);
|
->setMultiple(true);
|
||||||
$fields->insertAfter($tagsField, "Categories");
|
$fields->insertAfter($tagsField, "Categories");
|
||||||
|
|
||||||
@ -87,7 +89,9 @@ class BlogPost extends Page {
|
|||||||
"Content"
|
"Content"
|
||||||
);
|
);
|
||||||
$uploadField->getValidator()->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif'));
|
$uploadField->getValidator()->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif'));
|
||||||
|
});
|
||||||
|
|
||||||
|
$fields = parent::getCMSFields();
|
||||||
return $fields;
|
return $fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user