mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
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:
commit
f4242f3460
@ -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();
|
||||
|
@ -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();
|
||||
|
||||
$type = $this->dbObject("Type")->enumValues();
|
||||
$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);
|
||||
}
|
||||
|
||||
$fields->merge(array(
|
||||
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"))
|
||||
));
|
||||
$this->extend("updateCMSFields", $fields);
|
||||
return $fields;
|
||||
});
|
||||
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;
|
||||
|
@ -17,12 +17,12 @@ if(class_exists("Widget")) {
|
||||
);
|
||||
|
||||
public function getCMSFields() {
|
||||
$fields = FieldList::create();
|
||||
$this->beforeUpdateCMSFields(function($fields) {
|
||||
$fields->push(
|
||||
DropdownField::create("BlogID", _t("BlogCategoriesWidget.Blog", "Blog"), Blog::get()->map())
|
||||
);
|
||||
$this->extend("updateCMSFields", $fields);
|
||||
return $fields;
|
||||
});
|
||||
return parent::getCMSFields();
|
||||
}
|
||||
|
||||
public function getCategories() {
|
@ -19,13 +19,13 @@ if(class_exists("Widget")) {
|
||||
);
|
||||
|
||||
public function getCMSFields() {
|
||||
$fields = FieldList::create();
|
||||
$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"))
|
||||
));
|
||||
$this->extend("updateCMSFields", $fields);
|
||||
return $fields;
|
||||
});
|
||||
return parent::getCMSFields();
|
||||
}
|
||||
|
||||
public function getPosts() {
|
||||
|
@ -17,10 +17,10 @@ if(class_exists("Widget")) {
|
||||
);
|
||||
|
||||
public function getCMSFields() {
|
||||
$fields = FieldList::create();
|
||||
$this->beforeUpdateCMSFields(function($fields) {
|
||||
$fields->push(DropdownField::create("BlogID", _t("BlogTagsWidget.Blog", "Blog"), Blog::get()->map()));
|
||||
$this->extend("updateCMSFields", $fields);
|
||||
return $fields;
|
||||
});
|
||||
return parent::getCMSFields();
|
||||
}
|
||||
|
||||
public function getTags() {
|
||||
|
@ -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'
|
||||
|
Loading…
Reference in New Issue
Block a user