API Update Widget implementations in blog

This commit is contained in:
Robbie Averill 2017-01-18 17:12:06 +13:00
parent 98645af960
commit 5eb9ec879d
12 changed files with 187 additions and 62 deletions

View File

@ -22,7 +22,12 @@ mappings:
GridFieldBlogPostState: SilverStripe\Blog\Forms\GridField\GridFieldBlogPostState
GridFieldConfig_BlogPost: SilverStripe\Blog\Forms\GridField\GridFieldConfig_BlogPost
BlogArchiveWidget: SilverStripe\Blog\Widgets\BlogArchiveWidget
BlogArchiveWidget_Controller: SilverStripe\Blog\Widgets\BlogArchiveWidgetController
BlogCategoriesWidget: SilverStripe\Blog\Widgets\BlogCategoriesWidget
BlogCategoriesWidget_Controller: SilverStripe\Blog\Widgets\BlogCategoriesWidgetController
BlogRecentPostsWidget: SilverStripe\Blog\Widgets\BlogRecentPostsWidget
BlogRecentPostsWidget_Controller: SilverStripe\Blog\Widgets\BlogRecentPostsWidgetController
BlogTagsCloudWidget: SilverStripe\Blog\Widgets\BlogTagsCloudWidget
BlogTagsCloudWidget_Controller: SilverStripe\Blog\Widgets\BlogTagsCloudWidgetController
BlogTagsWidget: SilverStripe\Blog\Widgets\BlogTagsWidget
BlogTagsWidget_Controller: SilverStripe\Blog\Widgets\BlogTagsWidgetController

View File

@ -3,6 +3,7 @@
namespace SilverStripe\Blog\Forms\GridField;
use SilverStripe\Lumberjack\Forms\GridFieldConfig_Lumberjack;
use SilverStripe\Lumberjack\Forms\GridFieldSiteTreeState;
/**
* GridField config necessary for managing a SiteTree object.
@ -19,7 +20,7 @@ class GridFieldConfig_BlogPost extends GridFieldConfig_Lumberjack
{
parent::__construct($itemsPerPage);
$this->removeComponentsByType('SilverStripe\\Lumberjack\\Forms\\GridFieldSiteTreeState');
$this->removeComponentsByType(GridFieldSiteTreeState::class);
$this->addComponent(new GridFieldBlogPostState());
}
}

View File

@ -2,12 +2,16 @@
namespace SilverStripe\Blog\Widgets;
use SilverStripe\Blog\Model\Blog;
if (!class_exists('Widget')) {
if (!class_exists('\\SilverStripe\\Widgets\\Model\\Widget')) {
return;
}
use SilverStripe\Blog\Model\Blog;
use SilverStripe\Control\Controller;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\NumericField;
use SilverStripe\Widgets\Model\Widget;
/**
* @method Blog Blog()
*
@ -50,7 +54,7 @@ class BlogArchiveWidget extends Widget
* @var array
*/
private static $has_one = array(
'Blog' => 'SilverStripe\\Blog\\Model\\Blog',
'Blog' => Blog::class,
);
/**
@ -58,13 +62,11 @@ class BlogArchiveWidget extends Widget
*/
public function getCMSFields()
{
$self =& $this;
$this->beforeUpdateCMSFields(function ($fields) use ($self) {
$this->beforeUpdateCMSFields(function ($fields) {
/**
* @var Enum $archiveType
*/
$archiveType = $self->dbObject('ArchiveType');
$archiveType = $this->dbObject('ArchiveType');
$type = $archiveType->enumValues();
@ -76,7 +78,11 @@ class BlogArchiveWidget extends Widget
* @var FieldList $fields
*/
$fields->merge(array(
DropdownField::create('BlogID', _t('BlogArchiveWidget.Blog', 'SilverStripe\\Blog\\Model\\Blog'), Blog::get()->map()),
DropdownField::create(
'BlogID',
_t('BlogArchiveWidget.Blog', 'Blog'),
Blog::get()->map()
),
DropdownField::create('ArchiveType', _t('BlogArchiveWidget.ArchiveType', 'ArchiveType'), $type),
NumericField::create('NumberToDisplay', _t('BlogArchiveWidget.NumberToDisplay', 'No. to Display'))
));
@ -136,7 +142,3 @@ class BlogArchiveWidget extends Widget
return $archive;
}
}
class BlogArchiveWidget_Controller extends Widget_Controller
{
}

View File

@ -0,0 +1,14 @@
<?php
namespace SilverStripe\Blog\Widgets;
if (!class_exists('\\SilverStripe\\Widgets\\Model\\Widget')) {
return;
}
use SilverStripe\Widgets\Controllers\WidgetController;
class BlogArchiveWidgetController extends WidgetController
{
}

View File

@ -2,12 +2,17 @@
namespace SilverStripe\Blog\Widgets;
use SilverStripe\Blog\Model\Blog;
if (!class_exists('Widget')) {
if (!class_exists('\\SilverStripe\\Widgets\\Model\\Widget')) {
return;
}
use SilverStripe\Blog\Model\Blog;
use SilverStripe\Core\Convert;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\NumericField;
use SilverStripe\Widgets\Model\Widget;
/**
* @method Blog Blog()
*/
@ -41,7 +46,7 @@ class BlogCategoriesWidget extends Widget
* @var array
*/
private static $has_one = array(
'Blog' => 'SilverStripe\\Blog\\Model\\Blog',
'Blog' => Blog::class,
);
/**
@ -51,24 +56,44 @@ class BlogCategoriesWidget extends Widget
{
$this->beforeUpdateCMSFields(function (FieldList $fields) {
$fields[] = DropdownField::create(
'BlogID', _t('BlogCategoriesWidget.Blog', 'SilverStripe\\Blog\\Model\\Blog'), Blog::get()->map()
'BlogID',
_t('BlogCategoriesWidget.Blog', 'Blog'),
Blog::get()->map()
);
$fields[] = NumericField::create(
'Limit', _t('BlogCategoriesWidget.Limit.Label', 'Limit'), 0
'Limit',
_t('BlogCategoriesWidget.Limit.Label', 'Limit'),
0
)
->setDescription(_t('BlogCategoriesWidget.Limit.Description', 'Limit the number of categories shown by this widget (set to 0 to show all categories).'))
->setDescription(
_t(
'BlogCategoriesWidget.Limit.Description',
'Limit the number of categories shown by this widget (set to 0 to show all categories).'
)
)
->setMaxLength(3);
$fields[] = DropdownField::create(
'Order', _t('BlogCategoriesWidget.Sort.Label', 'Sort'), array('Title' => 'Title', 'Created' => 'Created', 'LastEdited' => 'Updated')
'Order',
_t('BlogCategoriesWidget.Sort.Label', 'Sort'),
array('Title' => 'Title', 'Created' => 'Created', 'LastEdited' => 'Updated')
)
->setDescription(_t('BlogCategoriesWidget.Sort.Description', 'Change the order of categories shown by this widget.'));
->setDescription(
_t('BlogCategoriesWidget.Sort.Description', 'Change the order of categories shown by this widget.')
);
$fields[] = DropdownField::create(
'Direction', _t('BlogCategoriesWidget.Direction.Label', 'Direction'), array('ASC' => 'Ascending', 'DESC' => 'Descending')
'Direction',
_t('BlogCategoriesWidget.Direction.Label', 'Direction'),
array('ASC' => 'Ascending', 'DESC' => 'Descending')
)
->setDescription(_t('BlogCategoriesWidget.Direction.Description', 'Change the direction of ordering of categories shown by this widget.'));
->setDescription(
_t(
'BlogCategoriesWidget.Direction.Description',
'Change the direction of ordering of categories shown by this widget.'
)
);
});
return parent::getCMSFields();
@ -99,6 +124,4 @@ class BlogCategoriesWidget extends Widget
}
}
class BlogCategoriesWidget_Controller extends Widget_Controller
{
}

View File

@ -0,0 +1,14 @@
<?php
namespace SilverStripe\Blog\Widgets;
if (!class_exists('\\SilverStripe\\Widgets\\Model\\Widget')) {
return;
}
use SilverStripe\Widgets\Controllers\WidgetController;
class BlogCategoriesWidgetController extends WidgetController
{
}

View File

@ -2,12 +2,15 @@
namespace SilverStripe\Blog\Widgets;
use SilverStripe\Blog\Model\Blog;
if (!class_exists('Widget')) {
if (!class_exists('\\SilverStripe\\Widgets\\Model\\Widget')) {
return;
}
use SilverStripe\Blog\Model\Blog;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\NumericField;
use SilverStripe\Widgets\Model\Widget;
/**
* @method Blog Blog()
*
@ -41,7 +44,7 @@ class BlogRecentPostsWidget extends Widget
* @var array
*/
private static $has_one = array(
'Blog' => 'SilverStripe\\Blog\\Model\\Blog',
'Blog' => Blog::class,
);
/**
@ -54,7 +57,7 @@ class BlogRecentPostsWidget extends Widget
* @var FieldList $fields
*/
$fields->merge(array(
DropdownField::create('BlogID', _t('BlogRecentPostsWidget.Blog', 'SilverStripe\\Blog\\Model\\Blog'), Blog::get()->map()),
DropdownField::create('BlogID', _t('BlogRecentPostsWidget.Blog', 'Blog'), Blog::get()->map()),
NumericField::create('NumberOfPosts', _t('BlogRecentPostsWidget.NumberOfPosts', 'Number of Posts'))
));
});
@ -78,7 +81,3 @@ class BlogRecentPostsWidget extends Widget
return array();
}
}
class BlogRecentPostsWidget_Controller extends Widget_Controller
{
}

View File

@ -0,0 +1,14 @@
<?php
namespace SilverStripe\Blog\Widgets;
if (!class_exists('\\SilverStripe\\Widgets\\Model\\Widget')) {
return;
}
use SilverStripe\Widgets\Controllers\WidgetController;
class BlogRecentPostsWidgetController extends WidgetController
{
}

View File

@ -2,12 +2,18 @@
namespace SilverStripe\Blog\Widgets;
use SilverStripe\Blog\Model\Blog;
if (!class_exists('Widget')) {
if (!class_exists('\\SilverStripe\\Widgets\\Model\\Widget')) {
return;
}
use SilverStripe\Blog\Model\Blog;
use SilverStripe\Core\Convert;
use SilverStripe\Forms\DropdownField;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DB;
use SilverStripe\Widgets\Model\Widget;
/**
* @method Blog Blog()
*/
@ -37,7 +43,7 @@ class BlogTagsCloudWidget extends Widget
* @var array
*/
private static $has_one = array(
'Blog' => 'SilverStripe\\Blog\\Model\\Blog',
'Blog' => Blog::class,
);
/**
@ -50,8 +56,11 @@ class BlogTagsCloudWidget extends Widget
* @var FieldList $fields
*/
$fields->push(
DropdownField::create('BlogID', _t('BlogTagsCloudWidget.Blog',
'SilverStripe\\Blog\\Model\\Blog'), Blog::get()->map())
DropdownField::create(
'BlogID',
_t('BlogTagsCloudWidget.Blog', 'Blog'),
Blog::get()->map()
)
);
});
@ -109,7 +118,3 @@ class BlogTagsCloudWidget extends Widget
return array();
}
}
class BlogTagsCloudWidget_Controller extends Widget_Controller
{
}

View File

@ -0,0 +1,13 @@
<?php
namespace SilverStripe\Blog\Widgets;
if (!class_exists('\\SilverStripe\\Widgets\\Model\\Widget')) {
return;
}
use SilverStripe\Widgets\Controllers\WidgetController;
class BlogTagsCloudWidgetController extends WidgetController
{
}

View File

@ -2,12 +2,17 @@
namespace SilverStripe\Blog\Widgets;
use SilverStripe\Blog\Model\Blog;
if (!class_exists('Widget')) {
if (!class_exists('\\SilverStripe\\Widgets\\Model\\Widget')) {
return;
}
use SilverStripe\Blog\Model\Blog;
use SilverStripe\Core\Convert;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\NumericField;
use SilverStripe\Widgets\Model\Widget;
/**
* @method Blog Blog()
*/
@ -41,7 +46,7 @@ class BlogTagsWidget extends Widget
* @var array
*/
private static $has_one = array(
'Blog' => 'SilverStripe\\Blog\\Model\\Blog',
'Blog' => Blog::class
);
/**
@ -51,24 +56,44 @@ class BlogTagsWidget extends Widget
{
$this->beforeUpdateCMSFields(function (Fieldlist $fields) {
$fields[] = DropdownField::create(
'BlogID', _t('BlogTagsWidget.Blog', 'SilverStripe\\Blog\\Model\\Blog'), Blog::get()->map()
'BlogID',
_t('BlogTagsWidget.Blog', 'Blog'),
Blog::get()->map()
);
$fields[] = NumericField::create(
'Limit', _t('BlogTagsWidget.Limit.Label', 'Limit'), 0
'Limit',
_t('BlogTagsWidget.Limit.Label', 'Limit'),
0
)
->setDescription(_t('BlogTagsWidget.Limit.Description', 'Limit the number of tags shown by this widget (set to 0 to show all tags).'))
->setDescription(
_t(
'BlogTagsWidget.Limit.Description',
'Limit the number of tags shown by this widget (set to 0 to show all tags).'
)
)
->setMaxLength(3);
$fields[] = DropdownField::create(
'Order', _t('BlogTagsWidget.Sort.Label', 'Sort'), array('Title' => 'Title', 'Created' => 'Created', 'LastEdited' => 'Updated')
'Order',
_t('BlogTagsWidget.Sort.Label', 'Sort'),
array('Title' => 'Title', 'Created' => 'Created', 'LastEdited' => 'Updated')
)
->setDescription(_t('BlogTagsWidget.Sort.Description', 'Change the order of tags shown by this widget.'));
->setDescription(
_t('BlogTagsWidget.Sort.Description', 'Change the order of tags shown by this widget.')
);
$fields[] = DropdownField::create(
'Direction', _t('BlogTagsWidget.Direction.Label', 'Direction'), array('ASC' => 'Ascending', 'DESC' => 'Descending')
'Direction',
_t('BlogTagsWidget.Direction.Label', 'Direction'),
array('ASC' => 'Ascending', 'DESC' => 'Descending')
)
->setDescription(_t('BlogTagsWidget.Direction.Description', 'Change the direction of ordering of tags shown by this widget.'));
->setDescription(
_t(
'BlogTagsWidget.Direction.Description',
'Change the direction of ordering of tags shown by this widget.'
)
);
});
return parent::getCMSFields();
@ -98,7 +123,3 @@ class BlogTagsWidget extends Widget
return $query;
}
}
class BlogTagsWidget_Controller extends Widget_Controller
{
}

View File

@ -0,0 +1,14 @@
<?php
namespace SilverStripe\Blog\Widgets;
if (!class_exists('\\SilverStripe\\Widgets\\Model\\Widget')) {
return;
}
use SilverStripe\Widgets\Controllers\WidgetController;
class BlogTagsWidgetController extends WidgetController
{
}