API Enable rename of widgets

This commit is contained in:
Damian Mooyman 2015-03-06 08:57:43 +13:00
parent fff7bca419
commit 89eac300c9
4 changed files with 65 additions and 22 deletions

View File

@ -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 {
}
}
}

View File

@ -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 {
}
}
}

View File

@ -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 {
}
}
}
}

View File

@ -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 {
}
}
}
}