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

@ -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"))
@ -84,5 +94,4 @@ if(class_exists("Widget")) {
class BlogArchiveWidget_Controller extends Widget_Controller {
}
}

View File

@ -10,17 +10,29 @@ if(class_exists("Widget")) {
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;
}
@ -38,5 +50,4 @@ if(class_exists("Widget")) {
class BlogCategoriesWidget_Controller extends Widget_Controller {
}
}

View File

@ -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"))
));
@ -43,5 +54,4 @@ if(class_exists("Widget")) {
class BlogRecentPostsWidget_Controller extends Widget_Controller {
}
}

View File

@ -10,15 +10,29 @@ if(class_exists("Widget")) {
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;
}
@ -36,5 +50,4 @@ if(class_exists("Widget")) {
class BlogTagsWidget_Controller extends Widget_Controller {
}
}