Merge pull request #152 from tractorcow/pulls/2.0/fix-archive

BUG Fix Type field conflict with core Widget field
This commit is contained in:
Christopher Pitt 2015-03-06 15:11:00 +13:00
commit f4242f3460
6 changed files with 35 additions and 35 deletions

View File

@ -20,7 +20,7 @@ class ArchiveWidget extends BlogArchiveWidget implements MigratableObject {
public function up() { public function up() {
if($this->DisplayMode) { if($this->DisplayMode) {
$this->Type = ($this->DisplayMode === 'year') ? 'Yearly' : 'Monthly'; $this->ArchiveType = ($this->DisplayMode === 'year') ? 'Yearly' : 'Monthly';
} }
$this->ClassName = 'BlogArchiveWidget'; $this->ClassName = 'BlogArchiveWidget';
$this->write(); $this->write();

View File

@ -12,7 +12,7 @@ if(class_exists("Widget")) {
private static $db = array( private static $db = array(
"NumberToDisplay" => "Int", "NumberToDisplay" => "Int",
"Type" => "Enum('Monthly, Yearly', 'Monthly')" "ArchiveType" => "Enum('Monthly,Yearly', 'Monthly')"
); );
private static $defaults = array( private static $defaults = array(
@ -24,20 +24,20 @@ if(class_exists("Widget")) {
); );
public function getCMSFields() { public function getCMSFields() {
$fields = parent::getCMSFields(); $self = $this;
$this->beforeUpdateCMSFields(function($fields) use ($self) {
$type = $this->dbObject("Type")->enumValues(); $type = $self->dbObject("ArchiveType")->enumValues();
foreach($type as $k => $v) { foreach($type as $k => $v) {
$type[$k] = _t("BlogArchiveWidget." . ucfirst(strtolower($v)), $v); $type[$k] = _t("BlogArchiveWidget." . ucfirst(strtolower($v)), $v);
} }
$fields->merge(array( $fields->merge(array(
DropdownField::create("BlogID", _t("BlogArchiveWidget.Blog", "Blog"), Blog::get()->map()), DropdownField::create("BlogID", _t("BlogArchiveWidget.Blog", "Blog"), Blog::get()->map()),
DropdownField::create("Type", _t("BlogArchiveWidget.Type", "Type"), $type), DropdownField::create("ArchiveType", _t("BlogArchiveWidget.ArchiveType", "ArchiveType"), $type),
NumericField::create("NumberToDisplay", _t("BlogArchiveWidget.NumberToDisplay", "No. to Display")) NumericField::create("NumberToDisplay", _t("BlogArchiveWidget.NumberToDisplay", "No. to Display"))
)); ));
$this->extend("updateCMSFields", $fields); });
return $fields; return parent::getCMSFields();
} }
@ -49,7 +49,7 @@ if(class_exists("Widget")) {
public function getArchive() { public function getArchive() {
$query = $this->Blog()->getBlogPosts()->dataQuery(); $query = $this->Blog()->getBlogPosts()->dataQuery();
if($this->Type == "Yearly") { if($this->ArchiveType == "Yearly") {
$query->groupBy("DATE_FORMAT(PublishDate, '%Y')"); $query->groupBy("DATE_FORMAT(PublishDate, '%Y')");
} else { } else {
$query->groupBy("DATE_FORMAT(PublishDate, '%Y-%M')"); $query->groupBy("DATE_FORMAT(PublishDate, '%Y-%M')");
@ -61,7 +61,7 @@ if(class_exists("Widget")) {
$archive = new ArrayList(); $archive = new ArrayList();
if($articles->count() > 0) { if($articles->count() > 0) {
foreach($articles as $article) { foreach($articles as $article) {
if($this->Type == "Yearly") { if($this->ArchiveType == "Yearly") {
$year = date('Y', strtotime($article->PublishDate)); $year = date('Y', strtotime($article->PublishDate));
$month = null; $month = null;
$title = $year; $title = $year;

View File

@ -17,12 +17,12 @@ if(class_exists("Widget")) {
); );
public function getCMSFields() { public function getCMSFields() {
$fields = FieldList::create(); $this->beforeUpdateCMSFields(function($fields) {
$fields->push( $fields->push(
DropdownField::create("BlogID", _t("BlogCategoriesWidget.Blog", "Blog"), Blog::get()->map()) DropdownField::create("BlogID", _t("BlogCategoriesWidget.Blog", "Blog"), Blog::get()->map())
); );
$this->extend("updateCMSFields", $fields); });
return $fields; return parent::getCMSFields();
} }
public function getCategories() { public function getCategories() {

View File

@ -19,13 +19,13 @@ if(class_exists("Widget")) {
); );
public function getCMSFields() { public function getCMSFields() {
$fields = FieldList::create(); $this->beforeUpdateCMSFields(function($fields) {
$fields->merge(array( $fields->merge(array(
DropdownField::create("BlogID", _t("BlogRecentPostsWidget.Blog", "Blog"), Blog::get()->map()), DropdownField::create("BlogID", _t("BlogRecentPostsWidget.Blog", "Blog"), Blog::get()->map()),
NumericField::create("NumberOfPosts", _t("BlogRecentPostsWidget.NumberOfPosts", "Number of Posts")) NumericField::create("NumberOfPosts", _t("BlogRecentPostsWidget.NumberOfPosts", "Number of Posts"))
)); ));
$this->extend("updateCMSFields", $fields); });
return $fields; return parent::getCMSFields();
} }
public function getPosts() { public function getPosts() {

View File

@ -17,10 +17,10 @@ if(class_exists("Widget")) {
); );
public function getCMSFields() { public function getCMSFields() {
$fields = FieldList::create(); $this->beforeUpdateCMSFields(function($fields) {
$fields->push(DropdownField::create("BlogID", _t("BlogTagsWidget.Blog", "Blog"), Blog::get()->map())); $fields->push(DropdownField::create("BlogID", _t("BlogTagsWidget.Blog", "Blog"), Blog::get()->map()));
$this->extend("updateCMSFields", $fields); });
return $fields; return parent::getCMSFields();
} }
public function getTags() { public function getTags() {

View File

@ -21,7 +21,7 @@ en:
NumberToDisplay: 'No. to Display' NumberToDisplay: 'No. to Display'
PLURALNAME: 'Blog Archive Widgets' PLURALNAME: 'Blog Archive Widgets'
SINGULARNAME: 'Blog Archive Widget' SINGULARNAME: 'Blog Archive Widget'
Type: Type ArchiveType: Type
BlogCategoriesWidget: BlogCategoriesWidget:
Blog: Blog Blog: Blog
PLURALNAME: 'Blog Categories Widgets' PLURALNAME: 'Blog Categories Widgets'