From be0e8e283aafddbcf45e359b2fc6c9e4366adbf5 Mon Sep 17 00:00:00 2001 From: James Cocker Date: Fri, 13 Jun 2014 16:19:15 +0100 Subject: [PATCH] Blog: Wrapped CMS fields in beforeUpdateCMSFields to allow for customisation --- model/Blog.php | 71 ++++++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/model/Blog.php b/model/Blog.php index 39c33d4..b8c846a 100755 --- a/model/Blog.php +++ b/model/Blog.php @@ -33,45 +33,48 @@ class Blog extends Page { public function getCMSFields() { - $fields = parent::getCMSFields(); + $this->beforeUpdateCMSFields(function($fields) { - $posts = $this->getBlogPosts(); - $excluded = $this->getExcludedSiteTreeClassNames(); - if(!empty($excluded)) { - $posts = $posts->filter("ClassName", $excluded); - $gridField = new GridField( - "BlogPost", - _t("Blog.BlogPosts", "Blog Posts"), - $posts, - GridFieldConfig_BlogPost::create() + $posts = $this->getBlogPosts(); + $excluded = $this->getExcludedSiteTreeClassNames(); + if(!empty($excluded)) { + $posts = $posts->filter("ClassName", $excluded); + $gridField = new GridField( + "BlogPost", + _t("Blog.BlogPosts", "Blog Posts"), + $posts, + GridFieldConfig_BlogPost::create() + ); + $fields->addFieldToTab("Root.BlogPosts", $gridField); + } + + // Create categories and tag config + $config = GridFieldConfig_RecordEditor::create(); + $config->removeComponentsByType("GridFieldAddNewButton"); + $config->addComponent(new GridFieldAddByDBField("buttons-before-left")); + + $categories = GridField::create( + "Categories", + _t("Blog.Categories", "Categories"), + $this->Categories(), + $config ); - $fields->addFieldToTab("Root.BlogPosts", $gridField); - } - // Create categories and tag config - $config = GridFieldConfig_RecordEditor::create(); - $config->removeComponentsByType("GridFieldAddNewButton"); - $config->addComponent(new GridFieldAddByDBField("buttons-before-left")); + $tags = GridField::create( + "Tags", + _t("Blog.Tags", "Tags"), + $this->Tags(), + $config + ); - $categories = GridField::create( - "Categories", - _t("Blog.Categories", "Categories"), - $this->Categories(), - $config - ); - - $tags = GridField::create( - "Tags", - _t("Blog.Tags", "Tags"), - $this->Tags(), - $config - ); - - $fields->addFieldsToTab("Root.BlogOptions", array( - $categories, - $tags - )); + $fields->addFieldsToTab("Root.BlogOptions", array( + $categories, + $tags + )); + }); + + $fields = parent::getCMSFields(); return $fields; }