FIX Fixed the beforeUpdateCMSFields and made them consistent

This commit is contained in:
micmania1 2014-07-27 06:34:43 +01:00
parent 78edab24ef
commit 9a77be6226
2 changed files with 23 additions and 21 deletions

View File

@ -33,10 +33,11 @@ class Blog extends Page {
public function getCMSFields() {
$this->beforeUpdateCMSFields(function($fields) {
$self =& $this;
$this->beforeUpdateCMSFields(function($fields) use ($self) {
$posts = $this->getBlogPosts();
$excluded = $this->getExcludedSiteTreeClassNames();
$posts = $self->getBlogPosts();
$excluded = $self->getExcludedSiteTreeClassNames();
if(!empty($excluded)) {
$posts = $posts->filter("ClassName", $excluded);
$gridField = new GridField(
@ -56,14 +57,14 @@ class Blog extends Page {
$categories = GridField::create(
"Categories",
_t("Blog.Categories", "Categories"),
$this->Categories(),
$self->Categories(),
$config
);
$tags = GridField::create(
"Tags",
_t("Blog.Tags", "Tags"),
$this->Tags(),
$self->Tags(),
$config
);

View File

@ -59,13 +59,8 @@ class BlogPost extends Page {
public function getCMSFields() {
// Assign to variable & pass for PHP <= 5.4 closure compatibility
$data = array(
"TagsMap" => $this->Parent()->Tags()->map()->toArray(),
"CategoryMap" => $this->Parent()->Categories()->map()->toArray()
);
$this->beforeUpdateCMSFields(function($fields) use ($data) {
$self =& $this;
$this->beforeUpdateCMSFields(function($fields) use ($self) {
// Add Publish date fields
$fields->insertAfter(
$publishDate = DatetimeField::create("PublishDate", _t("BlogPost.PublishDate", "Publish Date")),
@ -74,12 +69,18 @@ class BlogPost extends Page {
$publishDate->getDateField()->setConfig("showcalendar", true);
// Add Categories & Tags fields
$categoriesField = ListboxField::create("Categories",
_t("BlogPost.Categories", "Categories"), $data['CategoryMap'])->setMultiple(true);
$categoriesField = ListboxField::create(
"Categories",
_t("BlogPost.Categories", "Categories"),
$self->Parent()->Categories()->map()->toArray()
)->setMultiple(true);
$fields->insertAfter($categoriesField, "PublishDate");
$tagsField = ListboxField::create("Tags", _t("BlogPost.Tags", "Tags"), $data['TagsMap'])
->setMultiple(true);
$tagsField = ListboxField::create(
"Tags",
_t("BlogPost.Tags", "Tags"),
$self->Parent()->Tags()->map()->toArray()
)->setMultiple(true);
$fields->insertAfter($tagsField, "Categories");
// Add featured image