From 686112aa10b023115d0b6b9724a56b1800bb7e75 Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Fri, 6 Mar 2015 10:41:37 +1300 Subject: [PATCH] BUG Fix Type field conflict with core Widget field Type is used for the widget classname Better scaffolding of formfields Fix typo in filename --- code/compat/widgets/ArchiveWidget.php | 2 +- code/widgets/BlogArchiveWidget.php | 32 +++++++++---------- ...iesWIdget.php => BlogCategoriesWidget.php} | 12 +++---- code/widgets/BlogRecentPostsWidget.php | 14 ++++---- code/widgets/BlogTagsWidget.php | 8 ++--- lang/en.yml | 2 +- 6 files changed, 35 insertions(+), 35 deletions(-) rename code/widgets/{BlogCategoriesWIdget.php => BlogCategoriesWidget.php} (69%) diff --git a/code/compat/widgets/ArchiveWidget.php b/code/compat/widgets/ArchiveWidget.php index 6ea9b1d..84169f9 100644 --- a/code/compat/widgets/ArchiveWidget.php +++ b/code/compat/widgets/ArchiveWidget.php @@ -20,7 +20,7 @@ class ArchiveWidget extends BlogArchiveWidget implements MigratableObject { public function up() { if($this->DisplayMode) { - $this->Type = ($this->DisplayMode === 'year') ? 'Yearly' : 'Monthly'; + $this->ArchiveType = ($this->DisplayMode === 'year') ? 'Yearly' : 'Monthly'; } $this->ClassName = 'BlogArchiveWidget'; $this->write(); diff --git a/code/widgets/BlogArchiveWidget.php b/code/widgets/BlogArchiveWidget.php index fb8f981..0638d15 100644 --- a/code/widgets/BlogArchiveWidget.php +++ b/code/widgets/BlogArchiveWidget.php @@ -12,7 +12,7 @@ if(class_exists("Widget")) { private static $db = array( "NumberToDisplay" => "Int", - "Type" => "Enum('Monthly, Yearly', 'Monthly')" + "ArchiveType" => "Enum('Monthly,Yearly', 'Monthly')" ); private static $defaults = array( @@ -24,20 +24,20 @@ if(class_exists("Widget")) { ); public function getCMSFields() { - $fields = parent::getCMSFields(); + $self = $this; + $this->beforeUpdateCMSFields(function($fields) use ($self) { + $type = $self->dbObject("ArchiveType")->enumValues(); + foreach($type as $k => $v) { + $type[$k] = _t("BlogArchiveWidget." . ucfirst(strtolower($v)), $v); + } - $type = $this->dbObject("Type")->enumValues(); - foreach($type as $k => $v) { - $type[$k] = _t("BlogArchiveWidget." . ucfirst(strtolower($v)), $v); - } - - $fields->merge(array( - DropdownField::create("BlogID", _t("BlogArchiveWidget.Blog", "Blog"), Blog::get()->map()), - DropdownField::create("Type", _t("BlogArchiveWidget.Type", "Type"), $type), - NumericField::create("NumberToDisplay", _t("BlogArchiveWidget.NumberToDisplay", "No. to Display")) - )); - $this->extend("updateCMSFields", $fields); - return $fields; + $fields->merge(array( + DropdownField::create("BlogID", _t("BlogArchiveWidget.Blog", "Blog"), Blog::get()->map()), + DropdownField::create("ArchiveType", _t("BlogArchiveWidget.ArchiveType", "ArchiveType"), $type), + NumericField::create("NumberToDisplay", _t("BlogArchiveWidget.NumberToDisplay", "No. to Display")) + )); + }); + return parent::getCMSFields(); } @@ -49,7 +49,7 @@ if(class_exists("Widget")) { public function getArchive() { $query = $this->Blog()->getBlogPosts()->dataQuery(); - if($this->Type == "Yearly") { + if($this->ArchiveType == "Yearly") { $query->groupBy("DATE_FORMAT(PublishDate, '%Y')"); } else { $query->groupBy("DATE_FORMAT(PublishDate, '%Y-%M')"); @@ -61,7 +61,7 @@ if(class_exists("Widget")) { $archive = new ArrayList(); if($articles->count() > 0) { foreach($articles as $article) { - if($this->Type == "Yearly") { + if($this->ArchiveType == "Yearly") { $year = date('Y', strtotime($article->PublishDate)); $month = null; $title = $year; diff --git a/code/widgets/BlogCategoriesWIdget.php b/code/widgets/BlogCategoriesWidget.php similarity index 69% rename from code/widgets/BlogCategoriesWIdget.php rename to code/widgets/BlogCategoriesWidget.php index eb506ab..930dd4b 100644 --- a/code/widgets/BlogCategoriesWIdget.php +++ b/code/widgets/BlogCategoriesWidget.php @@ -17,12 +17,12 @@ if(class_exists("Widget")) { ); public function getCMSFields() { - $fields = FieldList::create(); - $fields->push( - DropdownField::create("BlogID", _t("BlogCategoriesWidget.Blog", "Blog"), Blog::get()->map()) - ); - $this->extend("updateCMSFields", $fields); - return $fields; + $this->beforeUpdateCMSFields(function($fields) { + $fields->push( + DropdownField::create("BlogID", _t("BlogCategoriesWidget.Blog", "Blog"), Blog::get()->map()) + ); + }); + return parent::getCMSFields(); } public function getCategories() { diff --git a/code/widgets/BlogRecentPostsWidget.php b/code/widgets/BlogRecentPostsWidget.php index 006aa68..72fbe29 100644 --- a/code/widgets/BlogRecentPostsWidget.php +++ b/code/widgets/BlogRecentPostsWidget.php @@ -19,13 +19,13 @@ if(class_exists("Widget")) { ); public function getCMSFields() { - $fields = FieldList::create(); - $fields->merge(array( - DropdownField::create("BlogID", _t("BlogRecentPostsWidget.Blog", "Blog"), Blog::get()->map()), - NumericField::create("NumberOfPosts", _t("BlogRecentPostsWidget.NumberOfPosts", "Number of Posts")) - )); - $this->extend("updateCMSFields", $fields); - return $fields; + $this->beforeUpdateCMSFields(function($fields) { + $fields->merge(array( + DropdownField::create("BlogID", _t("BlogRecentPostsWidget.Blog", "Blog"), Blog::get()->map()), + NumericField::create("NumberOfPosts", _t("BlogRecentPostsWidget.NumberOfPosts", "Number of Posts")) + )); + }); + return parent::getCMSFields(); } public function getPosts() { diff --git a/code/widgets/BlogTagsWidget.php b/code/widgets/BlogTagsWidget.php index ed6e33d..ce854bb 100644 --- a/code/widgets/BlogTagsWidget.php +++ b/code/widgets/BlogTagsWidget.php @@ -17,10 +17,10 @@ if(class_exists("Widget")) { ); public function getCMSFields() { - $fields = FieldList::create(); - $fields->push(DropdownField::create("BlogID", _t("BlogTagsWidget.Blog", "Blog"), Blog::get()->map())); - $this->extend("updateCMSFields", $fields); - return $fields; + $this->beforeUpdateCMSFields(function($fields) { + $fields->push(DropdownField::create("BlogID", _t("BlogTagsWidget.Blog", "Blog"), Blog::get()->map())); + }); + return parent::getCMSFields(); } public function getTags() { diff --git a/lang/en.yml b/lang/en.yml index 4b94e0e..e3267a6 100755 --- a/lang/en.yml +++ b/lang/en.yml @@ -21,7 +21,7 @@ en: NumberToDisplay: 'No. to Display' PLURALNAME: 'Blog Archive Widgets' SINGULARNAME: 'Blog Archive Widget' - Type: Type + ArchiveType: Type BlogCategoriesWidget: Blog: Blog PLURALNAME: 'Blog Categories Widgets'