From 89eac300c9b1843c8cbc1da172b954e4e0c6f838 Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Fri, 6 Mar 2015 08:57:43 +1300 Subject: [PATCH] API Enable rename of widgets --- code/widgets/BlogArchiveWidget.php | 21 +++++++++++++++------ code/widgets/BlogCategoriesWIdget.php | 23 +++++++++++++++++------ code/widgets/BlogRecentPostsWidget.php | 18 ++++++++++++++---- code/widgets/BlogTagsWidget.php | 25 +++++++++++++++++++------ 4 files changed, 65 insertions(+), 22 deletions(-) diff --git a/code/widgets/BlogArchiveWidget.php b/code/widgets/BlogArchiveWidget.php index fb8f981..0a87acc 100644 --- a/code/widgets/BlogArchiveWidget.php +++ b/code/widgets/BlogArchiveWidget.php @@ -3,7 +3,7 @@ if(class_exists("Widget")) { class BlogArchiveWidget extends Widget { - + private static $title = "Archive"; private static $cmsTitle = "Archive"; @@ -11,6 +11,7 @@ if(class_exists("Widget")) { private static $description = "Displays an archive list of posts."; private static $db = array( + "Title" => "Varchar(255)", "NumberToDisplay" => "Int", "Type" => "Enum('Monthly, Yearly', 'Monthly')" ); @@ -23,15 +24,24 @@ if(class_exists("Widget")) { "Blog" => "Blog", ); - public function getCMSFields() { - $fields = parent::getCMSFields(); + public function Title() { + return $this->getField('Title') ?: parent::Title(); + } + public function populateDefaults() { + parent::populateDefaults(); + $this->setField('Title', parent::Title()); + } + + public function getCMSFields() { $type = $this->dbObject("Type")->enumValues(); foreach($type as $k => $v) { $type[$k] = _t("BlogArchiveWidget." . ucfirst(strtolower($v)), $v); } + $fields = FieldList::create(); $fields->merge(array( + TextField::create('Title', 'Title', null, 255), 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")) @@ -57,7 +67,7 @@ if(class_exists("Widget")) { $articles = $this->Blog()->getBlogPosts()->setDataQuery($query); if($this->NumberToDisplay > 0) $articles = $articles->limit($this->NumberToDisplay); - + $archive = new ArrayList(); if($articles->count() > 0) { foreach($articles as $article) { @@ -82,7 +92,6 @@ if(class_exists("Widget")) { } class BlogArchiveWidget_Controller extends Widget_Controller { - - } + } } diff --git a/code/widgets/BlogCategoriesWIdget.php b/code/widgets/BlogCategoriesWIdget.php index eb506ab..5fc8741 100644 --- a/code/widgets/BlogCategoriesWIdget.php +++ b/code/widgets/BlogCategoriesWIdget.php @@ -3,24 +3,36 @@ if(class_exists("Widget")) { class BlogCategoriesWidget extends Widget { - + private static $title = "Categories"; private static $cmsTitle = "Blog Categories"; private static $description = "Displays a list of blog categories."; - private static $db = array(); + private static $db = array( + "Title" => "Varchar(255)", + ); private static $has_one = array( "Blog" => "Blog", ); + public function Title() { + return $this->getField('Title') ?: parent::Title(); + } + + public function populateDefaults() { + parent::populateDefaults(); + $this->setField('Title', parent::Title()); + } + public function getCMSFields() { $fields = FieldList::create(); - $fields->push( + $fields->merge(array( + TextField::create('Title', 'Title', null, 255), DropdownField::create("BlogID", _t("BlogCategoriesWidget.Blog", "Blog"), Blog::get()->map()) - ); + )); $this->extend("updateCMSFields", $fields); return $fields; } @@ -36,7 +48,6 @@ if(class_exists("Widget")) { } class BlogCategoriesWidget_Controller extends Widget_Controller { - - } + } } diff --git a/code/widgets/BlogRecentPostsWidget.php b/code/widgets/BlogRecentPostsWidget.php index 006aa68..2f869b3 100644 --- a/code/widgets/BlogRecentPostsWidget.php +++ b/code/widgets/BlogRecentPostsWidget.php @@ -3,7 +3,7 @@ if(class_exists("Widget")) { class BlogRecentPostsWidget extends Widget { - + private static $title = "Recent Posts"; private static $cmsTitle = "Recent Posts"; @@ -11,6 +11,7 @@ if(class_exists("Widget")) { private static $description = "Displays a list of recent blog posts."; private static $db = array( + "Title" => "Varchar(255)", "NumberOfPosts" => "Int", ); @@ -18,9 +19,19 @@ if(class_exists("Widget")) { "Blog" => "Blog", ); + public function Title() { + return $this->getField('Title') ?: parent::Title(); + } + + public function populateDefaults() { + parent::populateDefaults(); + $this->setField('Title', parent::Title()); + } + public function getCMSFields() { $fields = FieldList::create(); $fields->merge(array( + TextField::create('Title', 'Title', null, 255), DropdownField::create("BlogID", _t("BlogRecentPostsWidget.Blog", "Blog"), Blog::get()->map()), NumericField::create("NumberOfPosts", _t("BlogRecentPostsWidget.NumberOfPosts", "Number of Posts")) )); @@ -41,7 +52,6 @@ if(class_exists("Widget")) { } class BlogRecentPostsWidget_Controller extends Widget_Controller { - - } -} \ No newline at end of file + } +} diff --git a/code/widgets/BlogTagsWidget.php b/code/widgets/BlogTagsWidget.php index ed6e33d..19e4ffd 100644 --- a/code/widgets/BlogTagsWidget.php +++ b/code/widgets/BlogTagsWidget.php @@ -3,22 +3,36 @@ if(class_exists("Widget")) { class BlogTagsWidget extends Widget { - + private static $title = "Tags"; private static $cmsTitle = "Blog Tags"; private static $description = "Displays a list of blog tags."; - private static $db = array(); + private static $db = array( + "Title" => "Varchar(255)", + ); private static $has_one = array( "Blog" => "Blog", ); + public function Title() { + return $this->getField('Title') ?: parent::Title(); + } + + public function populateDefaults() { + parent::populateDefaults(); + $this->setField('Title', parent::Title()); + } + public function getCMSFields() { $fields = FieldList::create(); - $fields->push(DropdownField::create("BlogID", _t("BlogTagsWidget.Blog", "Blog"), Blog::get()->map())); + $fields->merge(array( + TextField::create('Title', 'Title', null, 255), + DropdownField::create("BlogID", _t("BlogTagsWidget.Blog", "Blog"), Blog::get()->map()) + )); $this->extend("updateCMSFields", $fields); return $fields; } @@ -34,7 +48,6 @@ if(class_exists("Widget")) { } class BlogTagsWidget_Controller extends Widget_Controller { - - } -} \ No newline at end of file + } +}