Merge pull request #469 from creative-commoners/pulls/3/further-ss4-compat

ENHANCEMENT -  SS4 compatibility
This commit is contained in:
Robbie Averill 2017-09-14 13:39:42 +12:00 committed by GitHub
commit de0e8e0100
33 changed files with 406 additions and 433 deletions

View File

@ -1,8 +1 @@
<?php
/**
* Fetches the name of the current module folder name.
*
* @return string
**/
define('BLOGGER_DIR', basename(dirname(__FILE__)));

View File

@ -54,8 +54,8 @@ For example in BlogPost:
```php
protected function getCandidateAuthors() {
if($this->config()->restrict_authors_to_group) {
return Group::get()->filter('Code', $this->config()->restrict_authors_to_group)->first()->Members();
if($this->config()->get('restrict_authors_to_group')) {
return Group::get()->filter('Code', $this->config()->get('restrict_authors_to_group'))->first()->Members();
} else {
$list = Member::get();
$this->extend('updateCandidateAuthors', $list);

View File

@ -8,10 +8,10 @@ gulp.task("scss", function () {
.pipe(gulp.dest("./css"));
});
gulp.task('watch', ['scss'], function() {
gulp.task('watch', ['scss'], function () {
gulp.watch('./scss/*.scss', ['scss']);
});
gulp.task('default', ['scss'], function() {
gulp.task('default', ['scss'], function () {
// noop
});

192
js/cms.js
View File

@ -1,6 +1,6 @@
(function ($) {
$.entwine('ss', function ($) {
$.entwine('ss', function ($) {
/**
* The page success/error message sits outside of the html block
@ -10,136 +10,136 @@
* @see https://github.com/silverstripe/silverstripe-blog/issues/210
*/
$('.cms-content-fields > #Form_EditForm_error').entwine({
'onadd': function() {
'onadd': function () {
var $target = $('.blog-admin-outer');
if($target.length == 1) {
if ($target.length == 1) {
$target.prepend(this);
}
}
});
/**
* Register expandable help text functions with fields.
*/
$('.toggle-description').entwine({
'onadd': function () {
var $this = $(this);
/**
* Register expandable help text functions with fields.
*/
$('.toggle-description').entwine({
'onadd': function () {
var $this = $(this);
/**
* Prevent multiple events being added.
*/
if ($this.hasClass('toggle-description-enabled')) {
return;
}
/**
* Prevent multiple events being added.
*/
if ($this.hasClass('toggle-description-enabled')) {
return;
}
$this.addClass('toggle-description-enabled');
$this.addClass('toggle-description-enabled');
/**
* Toggle next description when button is clicked.
*/
var shown = false;
/**
* Toggle next description when button is clicked.
*/
var shown = false;
$this.on('click', function() {
$this.parent().next('.description')[shown ? 'hide' : 'show']();
$this.on('click', function () {
$this.parent().next('.description')[shown ? 'hide' : 'show']();
$this.toggleClass('toggle-description-shown');
$this.toggleClass('toggle-description-shown');
shown = !shown;
});
shown = !shown;
});
/**
* Hide next description by default.
*/
$this.parent().next('.description').hide();
/**
* Hide next description by default.
*/
$this.parent().next('.description').hide();
/**
* Add classes to correct inherited layout issues in a small context.
*/
$this.parent().addClass('toggle-description-correct-right');
$this.parent().prev('.middleColumn').addClass('toggle-description-correct-middle');
$this.parent().next('.description').addClass('toggle-description-correct-description');
}
});
/**
* Add classes to correct inherited layout issues in a small context.
*/
$this.parent().addClass('toggle-description-correct-right');
$this.parent().prev('.middleColumn').addClass('toggle-description-correct-middle');
$this.parent().next('.description').addClass('toggle-description-correct-description');
}
});
/**
* Custom merge actions for tags and categories
*/
$('.MergeAction').entwine({
'onadd': function() {
var $this = $(this);
/**
* Custom merge actions for tags and categories
*/
$('.MergeAction').entwine({
'onadd': function () {
var $this = $(this);
$this.on('click', 'select', function() {
return false;
});
$this.on('click', 'select', function () {
return false;
});
$this.children('button').each(function(i, button) {
var $button = $(button);
var $select = $button.prev('select');
$this.children('button').each(function (i, button) {
var $button = $(button);
var $select = $button.prev('select');
$button.before('<input type="hidden" name="' + $button.attr('data-target') + '" value="' + $select.val() + '" />');
});
$button.before('<input type="hidden" name="' + $button.attr('data-target') + '" value="' + $select.val() + '" />');
});
$this.on('change', 'select', function(e) {
var $target = $(e.target);
$this.on('change', 'select', function (e) {
var $target = $(e.target);
$target.next('input').val($target.val());
});
$target.next('input').val($target.val());
});
$this.children('button, select').hide();
$this.children('button, select').hide();
$this.on('click', '.MergeActionReveal', function(e) {
var $target = $(e.target);
$this.on('click', '.MergeActionReveal', function (e) {
var $target = $(e.target);
$target.parent().children('button, select').show();
$target.hide();
$target.parent().children('button, select').show();
$target.hide();
return false;
});
}
});
return false;
});
}
});
/**
* Customise the cms-panel behaviour for blog sidebar
*
* see LeftAndMain.Panel.js for base behaviour
*/
$('.blog-admin-sidebar.cms-panel').entwine({
MinInnerWidth: 620,
onadd: function() {
this._super();
this.updateLayout();
/**
* Customise the cms-panel behaviour for blog sidebar
*
* see LeftAndMain.Panel.js for base behaviour
*/
$('.blog-admin-sidebar.cms-panel').entwine({
MinInnerWidth: 620,
onadd: function () {
this._super();
this.updateLayout();
// If this panel is open and the left hand column is smaller than the minimum, contract it instead
if(!this.hasClass('collapsed') && ($(".blog-admin-outer").width() < this.getMinInnerWidth())) {
this.collapsePanel();
}
// If this panel is open and the left hand column is smaller than the minimum, contract it instead
if (!this.hasClass('collapsed') && ($(".blog-admin-outer").width() < this.getMinInnerWidth())) {
this.collapsePanel();
}
window.onresize = function() {
window.onresize = function () {
this.updateLayout();
}.bind(this);
},
togglePanel: function(bool, silent) {
this._super(bool, silent);
this.updateLayout();
},
/**
* Adjust minimum width of content to account for extra panel
*
* @returns {undefined}
*/
updateLayout: function() {
},
togglePanel: function (bool, silent) {
this._super(bool, silent);
this.updateLayout();
},
/**
* Adjust minimum width of content to account for extra panel
*
* @returns {undefined}
*/
updateLayout: function () {
$(this).css('height', '100%');
var currentHeight = $(this).outerHeight();
var bottomHeight = $('.cms-content-actions').eq(0).outerHeight();
$(this).css('height', (currentHeight - bottomHeight) + "px");
$(this).css('bottom', bottomHeight + "px");
$('.cms-container').updateLayoutOptions({
minContentWidth: 820 + this.width()
});
$('.cms-container').updateLayoutOptions({
minContentWidth: 820 + this.width()
});
}
});
}
});
});
});
})(jQuery);

View File

@ -23,11 +23,11 @@ class GridFieldCategorisationConfig extends GridFieldConfig_RecordEditor
$this->removeComponentsByType('SilverStripe\\Forms\\GridField\\GridFieldAddNewButton');
$this->addComponent(
new GridFieldAddByDBField('buttons-before-left')
GridFieldAddByDBField::create('buttons-before-left')
);
$this->addComponent(
new GridFieldMergeAction($mergeRecords, $parentType, $parentMethod, $childMethod)
GridFieldMergeAction::create($mergeRecords, $parentType, $parentMethod, $childMethod)
);
/**
@ -36,11 +36,11 @@ class GridFieldCategorisationConfig extends GridFieldConfig_RecordEditor
$columns = $this->getComponentByType('SilverStripe\\Forms\\GridField\\GridFieldDataColumns');
$columns->setFieldFormatting(
array(
[
'BlogPostsCount' => function ($value, CategorisationObject $item) {
return $item->BlogPosts()->Count();
}
)
]
);
$this->changeColumnOrder();
@ -57,12 +57,12 @@ class GridFieldCategorisationConfig extends GridFieldConfig_RecordEditor
$columns = $this->getComponentByType('SilverStripe\\Forms\\GridField\\GridFieldDataColumns');
$columns->setDisplayFields(
array(
[
'Title' => 'Title',
'BlogPostsCount' => 'Posts',
'MergeAction' => 'MergeAction',
'Actions' => 'Actions'
)
]
);
}
}

View File

@ -9,7 +9,7 @@ class GridFieldFormAction extends GridField_FormAction
/**
* @var array
*/
protected $extraAttributes = array();
protected $extraAttributes = [];
/**
* @param array $attributes

View File

@ -4,16 +4,16 @@ namespace SilverStripe\Blog\Admin;
use SilverStripe\Blog\Admin\GridFieldFormAction;
use SilverStripe\Control\Controller;
use SilverStripe\Core\Injector\Injectable;
use Silverstripe\Forms\DropdownField;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridField_ActionProvider;
use SilverStripe\Forms\GridField\GridField_ColumnProvider;
/**
* @package blog
*/
class GridFieldMergeAction implements GridField_ColumnProvider, GridField_ActionProvider
{
use Injectable;
/**
* List of records to show in the MergeAction column.
*
@ -48,7 +48,7 @@ class GridFieldMergeAction implements GridField_ColumnProvider, GridField_Action
* @param string $parentMethod
* @param string $childMethod
*/
public function __construct($records = array(), $parentType, $parentMethod, $childMethod)
public function __construct($records = [], $parentType, $parentMethod, $childMethod)
{
$this->records = $records;
$this->parentType = $parentType;
@ -73,7 +73,7 @@ class GridFieldMergeAction implements GridField_ColumnProvider, GridField_Action
*/
public function getColumnsHandled($gridField)
{
return array('MergeAction');
return ['MergeAction'];
}
/**
@ -86,20 +86,20 @@ class GridFieldMergeAction implements GridField_ColumnProvider, GridField_Action
$dropdown->setAttribute('id', 'Target_'.$record->ID);
$prefix = strtolower($this->parentMethod . '-' . $this->childMethod);
$action = new GridFieldFormAction(
$action = GridFieldFormAction::create(
$gridField,
'MergeAction' . $record->ID,
'Move',
'merge',
array(
[
'record' => $record->ID,
'target' => $prefix . '-target-record-' . $record->ID,
)
]
);
$action->setExtraAttributes(array(
$action->setExtraAttributes([
'data-target' => $prefix . '-target-record-' . $record->ID
));
]);
return $dropdown->Field() . $action->Field() . '<a title="Move posts to" class="MergeActionReveal">move posts to</a>';
}
@ -112,7 +112,7 @@ class GridFieldMergeAction implements GridField_ColumnProvider, GridField_Action
*/
public function getColumnAttributes($gridField, $record, $columnName)
{
return array('class' => 'MergeAction');
return ['class' => 'MergeAction'];
}
/**
@ -120,7 +120,7 @@ class GridFieldMergeAction implements GridField_ColumnProvider, GridField_Action
*/
public function getColumnMetadata($gridField, $columnName)
{
return array('title' => 'Move posts to');
return ['title' => 'Move posts to'];
}
/**
@ -128,7 +128,7 @@ class GridFieldMergeAction implements GridField_ColumnProvider, GridField_Action
*/
public function getActions($gridField)
{
return array('merge');
return ['merge'];
}
/**

View File

@ -2,6 +2,8 @@
namespace SilverStripe\Blog\Forms\GridField;
use SilverStripe\Core\Injector\Injectable;
use SilverStripe\Core\Manifest\ModuleLoader;
use UnexpectedValueException;
use SilverStripe\Control\Controller;
use SilverStripe\Core\Convert;
@ -15,14 +17,10 @@ use SilverStripe\Security\Security;
use SilverStripe\View\ArrayData;
use SilverStripe\View\Requirements;
/**
* Adds a component which allows a user to add a new DataObject by database field.
*
* @package silverstripe
* @subpackage blog
*/
class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLProvider
{
use Injectable;
/**
* HTML Fragment to render the field.
*
@ -59,9 +57,9 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
*/
public function getActions($gridField)
{
return array(
return [
'add',
);
];
}
/**
@ -86,7 +84,7 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
/**
* @var DataObject $obj
*/
$obj = new $objClass();
$obj = $objClass::create();
if ($obj->hasField($dbField)) {
$obj->setCastedField($dbField, $data['gridfieldaddbydbfield'][$obj->ClassName][$dbField]);
@ -96,12 +94,12 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
if (!$id) {
$gridField->setCustomValidationMessage(
_t(
'GridFieldAddByDBField.AddFail',
__CLASS__ . '.AddFail',
'Unable to save {class} to the database.',
'Unable to add the DataObject.',
array(
[
'class' => get_class($obj),
)
]
)
);
}
@ -109,12 +107,12 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
return Security::permissionFailure(
Controller::curr(),
_t(
'GridFieldAddByDBField.PermissionFail',
__CLASS__ . '.PermissionFail',
'You don\'t have permission to create a {class}.',
'Unable to add the DataObject.',
array(
[
'class' => get_class($obj)
)
]
)
);
}
@ -161,7 +159,7 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
*/
public function getHTMLFragments($gridField)
{
Requirements::javascript(BLOGGER_DIR . '/js/gridfieldaddbydbfield.js');
Requirements::javascript(ModuleLoader::getModule('silverstripe/blog')->getRelativeResourcePath('js/gridfieldaddbydbfield.js'));
/**
* @var DataList $dataList
@ -188,11 +186,11 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
->setAttribute('placeholder', $obj->fieldLabel($dbField))
->addExtraClass('no-change-track');
$addAction = new GridField_FormAction(
$addAction = GridField_FormAction::create(
$gridField,
'add',
_t(
'GridFieldAddByDBField.Add',
__CLASS__ . '.Add',
'Add {name}',
'Add button text',
['name' => $obj->i18n_singular_name()]
@ -203,12 +201,12 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
$addAction->setAttribute('data-icon', 'add');
$addAction->addExtraClass('btn btn-primary');
$forTemplate = new ArrayData(array());
$forTemplate = ArrayData::create([]);
$forTemplate->Fields = new ArrayList();
$forTemplate->Fields = ArrayList::create();
$forTemplate->Fields->push($textField);
$forTemplate->Fields->push($addAction);
return array($this->targetFragment => $forTemplate->renderWith(self::class));
return [$this->targetFragment => $forTemplate->renderWith(self::class)];
}
}

View File

@ -3,6 +3,7 @@
namespace SilverStripe\Blog\Forms\GridField;
use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Core\Manifest\ModuleLoader;
use SilverStripe\Lumberjack\Forms\GridFieldSiteTreeState;
use SilverStripe\View\Requirements;
@ -10,8 +11,6 @@ use SilverStripe\View\Requirements;
* Provides a component to the {@link GridField} which tells the user whether or not a blog post
* has been published and when.
*
* @package silverstripe
* @subpackage blog
*/
class GridFieldBlogPostState extends GridFieldSiteTreeState
{
@ -21,12 +20,12 @@ class GridFieldBlogPostState extends GridFieldSiteTreeState
public function getColumnContent($gridField, $record, $columnName)
{
if ($columnName == 'State') {
Requirements::css(BLOGGER_DIR . '/css/cms.css');
Requirements::css(ModuleLoader::getModule('silverstripe/blog')->getRelativeResourcePath('css/cms.css'));
if ($record instanceof BlogPost) {
$modifiedLabel = '';
if ($record->isModifiedOnStage) {
$modifiedLabel = '<span class="modified">' . _t('GridFieldBlogPostState.Modified') . '</span>';
$modifiedLabel = '<span class="modified">' . _t(__CLASS__ . '.Modified') . '</span>';
}
if (!$record->isPublished()) {
@ -36,12 +35,12 @@ class GridFieldBlogPostState extends GridFieldSiteTreeState
$lastEdited = $record->dbObject('LastEdited');
return _t(
'GridFieldBlogPostState.Draft',
__CLASS__ . '.Draft',
'<i class="btn-icon gridfield-icon btn-icon-pencil"></i> Saved as Draft on {date}',
'State for when a post is saved.',
array(
[
'date' => $lastEdited->FormatFromSettings(),
)
]
);
}
@ -52,22 +51,22 @@ class GridFieldBlogPostState extends GridFieldSiteTreeState
if (strtotime($record->PublishDate) > time()) {
return _t(
'GridFieldBlogPostState.Timer',
__CLASS__ . '.Timer',
'<i class="gridfield-icon blog-icon-timer"></i> Publish at {date}',
'State for when a post is published.',
array(
[
'date' => $publishDate->FormatFromSettings(),
)
]
) . $modifiedLabel;
}
return _t(
'GridFieldBlogPostState.Published',
__CLASS__ . '.Published',
'<i class="btn-icon gridfield-icon btn-icon-accept"></i> Published on {date}',
'State for when a post is published.',
array(
[
'date' => $publishDate->FormatFromSettings(),
)
]
) . $modifiedLabel;
}
}
@ -92,12 +91,12 @@ class GridFieldBlogPostState extends GridFieldSiteTreeState
$class = 'gridfield-icon published';
}
return array(
return [
'class' => $class,
);
];
}
}
return array();
return [];
}
}

View File

@ -8,8 +8,6 @@ use SilverStripe\Lumberjack\Forms\GridFieldSiteTreeState;
/**
* GridField config necessary for managing a SiteTree object.
*
* @package silverstripe
* @subpackage blog
*/
class GridFieldConfig_BlogPost extends GridFieldConfig_Lumberjack
{
@ -21,6 +19,6 @@ class GridFieldConfig_BlogPost extends GridFieldConfig_Lumberjack
parent::__construct($itemsPerPage);
$this->removeComponentsByType(GridFieldSiteTreeState::class);
$this->addComponent(new GridFieldBlogPostState());
$this->addComponent(GridFieldBlogPostState::create());
}
}

View File

@ -14,6 +14,7 @@ use SilverStripe\CMS\Controllers\RootURLController;
use SilverStripe\Control\Controller;
use SilverStripe\Control\RSS\RSSFeed;
use SilverStripe\Core\Convert;
use SilverStripe\Core\Manifest\ModuleLoader;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\ListboxField;
use SilverStripe\Forms\NumericField;
@ -27,14 +28,12 @@ use SilverStripe\Security\Group;
use SilverStripe\Security\Member;
use SilverStripe\Security\Permission;
use SilverStripe\Security\PermissionProvider;
use SilverStripe\Security\Security;
use SilverStripe\View\Requirements;
/**
* Blog Holder
*
* @package silverstripe
* @subpackage blog
*
* @method HasManyList Tags() List of tags in this blog
* @method HasManyList Categories() List of categories in this blog
* @method ManyManyList Editors() List of editors
@ -88,48 +87,48 @@ class Blog extends Page implements PermissionProvider
/**
* @var array
*/
private static $db = array(
private static $db = [
'PostsPerPage' => 'Int',
);
];
/**
* @var array
*/
private static $has_many = array(
private static $has_many = [
'Tags' => BlogTag::class,
'Categories' => BlogCategory::class,
);
];
/**
* @var array
*/
private static $many_many = array(
private static $many_many = [
'Editors' => Member::class,
'Writers' => Member::class,
'Contributors' => Member::class,
);
];
/**
* @var array
*/
private static $allowed_children = array(
private static $allowed_children = [
BlogPost::class,
);
];
/**
* @var array
*/
private static $extensions = array(
private static $extensions = [
BlogFilter::class,
);
];
/**
* @var array
*/
private static $defaults = array(
private static $defaults = [
'ProvideComments' => false,
'PostsPerPage' => 10
);
];
/**
* @var string
@ -143,8 +142,9 @@ class Blog extends Page implements PermissionProvider
*/
public function getCMSFields()
{
Requirements::css(BLOGGER_DIR . '/css/cms.css');
Requirements::javascript(BLOGGER_DIR . '/js/cms.js');
$module = ModuleLoader::getModule('silverstripe/blog');
Requirements::css($module->getRelativeResourcePath('css/cms.css'));
Requirements::javascript($module->getRelativeResourcePath('js/cms.js'));
$this->beforeUpdateCMSFields(function ($fields) {
if (!$this->canEdit()) {
@ -153,7 +153,7 @@ class Blog extends Page implements PermissionProvider
$categories = GridField::create(
'Categories',
_t('Blog.Categories', 'Categories'),
_t(__CLASS__ . '.Categories', 'Categories'),
$this->Categories(),
GridFieldCategorisationConfig::create(
15,
@ -166,7 +166,7 @@ class Blog extends Page implements PermissionProvider
$tags = GridField::create(
'Tags',
_t('Blog.Tags', 'Tags'),
_t(__CLASS__ . '.Tags', 'Tags'),
$this->Tags(),
GridFieldCategorisationConfig::create(
15,
@ -182,10 +182,10 @@ class Blog extends Page implements PermissionProvider
*/
$fields->addFieldsToTab(
'Root.Categorisation',
array(
[
$categories,
$tags
)
]
);
$fields->findOrMakeTab('Root.Categorisation')->addExtraClass('blog-cms-categorisation');
@ -216,7 +216,7 @@ class Blog extends Page implements PermissionProvider
protected function getMember($member = null)
{
if (!$member) {
$member = Member::currentUser();
$member = Security::getCurrentUser();
}
if (is_numeric($member)) {
@ -284,15 +284,15 @@ class Blog extends Page implements PermissionProvider
}
if ($this->isEditor($member)) {
return _t('Blog.EDITOR', 'Editor');
return _t(__CLASS__ . '.EDITOR', 'Editor');
}
if ($this->isWriter($member)) {
return _t('Blog.WRITER', 'Writer');
return _t(__CLASS__ . '.WRITER', 'Writer');
}
if ($this->isContributor($member)) {
return _t('Blog.CONTRIBUTOR', 'Contributor');
return _t(__CLASS__ . '.CONTRIBUTOR', 'Contributor');
}
return null;
@ -351,7 +351,7 @@ class Blog extends Page implements PermissionProvider
$fields->addFieldToTab(
'Root.Settings',
NumericField::create('PostsPerPage', _t('Blog.PostsPerPage', 'Posts Per Page'))
NumericField::create('PostsPerPage', _t(__CLASS__ . '.PostsPerPage', 'Posts Per Page'))
);
$members = $this->getCandidateUsers()->map()->toArray();
@ -408,11 +408,11 @@ class Blog extends Page implements PermissionProvider
$fields->addFieldsToTab(
'Root.Users',
array(
[
$editorField,
$writerField,
$contributorField
)
]
);
return $fields;
@ -425,13 +425,13 @@ class Blog extends Page implements PermissionProvider
*/
protected function getCandidateUsers()
{
if ($this->config()->grant_user_access) {
if ($this->config()->get('grant_user_access')) {
$list = Member::get();
$this->extend('updateCandidateUsers', $list);
return $list;
} else {
return Permission::get_members_by_permission(
$this->config()->grant_user_permission
$this->config()->get('grant_user_permission')
);
}
}
@ -528,7 +528,7 @@ class Blog extends Page implements PermissionProvider
sprintf('"SiteTree%s"."ID" = "BlogPost%s"."ID"', $stage, $stage)
);
$conn = DB::getConn();
$conn = DB::get_conn();
// Filter by year
$yearCond = $conn->formattedDatetimeClause('"BlogPost"."PublishDate"', '%Y');
@ -588,7 +588,7 @@ class Blog extends Page implements PermissionProvider
*/
public function getLumberjackTitle()
{
return _t('Blog.LumberjackTitle', 'Blog Posts');
return _t(__CLASS__ . '.LumberjackTitle', 'Blog Posts');
}
/**
@ -606,20 +606,20 @@ class Blog extends Page implements PermissionProvider
*/
public function providePermissions()
{
return array(
Blog::MANAGE_USERS => array(
return [
Blog::MANAGE_USERS => [
'name' => _t(
'Blog.PERMISSION_MANAGE_USERS_DESCRIPTION',
__CLASS__ . '.PERMISSION_MANAGE_USERS_DESCRIPTION',
'Manage users for individual blogs'
),
'help' => _t(
'Blog.PERMISSION_MANAGE_USERS_HELP',
__CLASS__ . '.PERMISSION_MANAGE_USERS_HELP',
'Allow assignment of Editors, Writers, or Contributors to blogs'
),
'category' => _t('Blog.PERMISSIONS_CATEGORY', 'Blog permissions'),
'category' => _t(__CLASS__ . '.PERMISSIONS_CATEGORY', 'Blog permissions'),
'sort' => 100
)
);
]
];
}
/**
@ -636,7 +636,7 @@ class Blog extends Page implements PermissionProvider
*/
protected function assignGroup()
{
if (!$this->config()->grant_user_access) {
if (!$this->config()->get('grant_user_access')) {
return;
}
@ -644,7 +644,7 @@ class Blog extends Page implements PermissionProvider
// Must check if the method exists or else an error occurs when changing page type
if ($this->hasMethod('Editors')) {
foreach (array($this->Editors(), $this->Writers(), $this->Contributors()) as $levels) {
foreach ([$this->Editors(), $this->Writers(), $this->Contributors()] as $levels) {
foreach ($levels as $user) {
if (!$user->inGroup($group)) {
$user->Groups()->add($group);
@ -661,7 +661,7 @@ class Blog extends Page implements PermissionProvider
*/
protected function getUserGroup()
{
$code = $this->config()->grant_user_group;
$code = $this->config()->get('grant_user_group');
$group = Group::get()->filter('Code', $code)->first();
@ -676,7 +676,7 @@ class Blog extends Page implements PermissionProvider
$group->write();
$permission = Permission::create();
$permission->Code = $this->config()->grant_user_permission;
$permission->Code = $this->config()->get('grant_user_permission');
$group->Permissions()->add($permission);

View File

@ -11,9 +11,7 @@ use SilverStripe\ORM\DataObject;
/**
* A blog category for generalising blog posts.
*
* @package silverstripe
* @subpackage blog
*
*
* @method Blog Blog()
*
* @property string $Title
@ -42,24 +40,24 @@ class BlogCategory extends DataObject implements CategorisationObject
/**
* @var array
*/
private static $db = array(
private static $db = [
'Title' => 'Varchar(255)',
'URLSegment' => 'Varchar(255)'
);
];
/**
* @var array
*/
private static $has_one = array(
private static $has_one = [
'Blog' => Blog::class,
);
];
/**
* @var array
*/
private static $belongs_many_many = array(
private static $belongs_many_many = [
'BlogPosts' => BlogPost::class,
);
];
/**
* {@inheritdoc}
@ -74,6 +72,6 @@ class BlogCategory extends DataObject implements CategorisationObject
*/
protected function getDuplicateError()
{
return _t('BlogCategory.Duplicate', 'A blog category already exists with that name.');
return _t(__CLASS__ . '.Duplicate', 'A blog category already exists with that name.');
}
}

View File

@ -9,40 +9,36 @@ use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\ORM\PaginatedList;
use SilverStripe\Security\Member;
/**
* @package silverstripe
* @subpackage blog
*/
class BlogController extends PageController
{
/**
* @var array
*/
private static $allowed_actions = array(
private static $allowed_actions = [
'archive',
'tag',
'category',
'rss',
'profile'
);
];
/**
* @var array
*/
private static $url_handlers = array(
private static $url_handlers = [
'tag/$Tag!/$Rss' => 'tag',
'category/$Category!/$Rss' => 'category',
'archive/$Year!/$Month/$Day' => 'archive',
'profile/$URLSegment!' => 'profile'
);
];
/**
* @var array
*/
private static $casting = array(
private static $casting = [
'MetaTitle' => 'Text',
'FilterDescription' => 'Text'
);
];
/**
* The current Blog Post DataList query.
@ -247,7 +243,7 @@ class BlogController extends PageController
$tag = $this->request->param('Tag');
if ($tag) {
return $dataRecord->Tags()
->filter('URLSegment', array($tag, rawurlencode($tag)))
->filter('URLSegment', [$tag, rawurlencode($tag)])
->first();
}
return null;
@ -291,7 +287,7 @@ class BlogController extends PageController
$category = $this->request->param('Category');
if ($category) {
return $dataRecord->Categories()
->filter('URLSegment', array($category, rawurlencode($category)))
->filter('URLSegment', [$category, rawurlencode($category)])
->first();
}
return null;
@ -323,52 +319,52 @@ class BlogController extends PageController
*/
public function getFilterDescription()
{
$items = array();
$items = [];
$list = $this->PaginatedList();
$currentPage = $list->CurrentPage();
if ($currentPage > 1) {
$items[] = _t(
'Blog.FILTERDESCRIPTION_PAGE',
'SilverStripe\\Blog\\Model\\Blog.FILTERDESCRIPTION_PAGE',
'Page {page}',
null,
array(
[
'page' => $currentPage
)
]
);
}
if ($author = $this->getCurrentProfile()) {
$items[] = _t(
'Blog.FILTERDESCRIPTION_AUTHOR',
'SilverStripe\\Blog\\Model\\Blog.FILTERDESCRIPTION_AUTHOR',
'By {author}',
null,
array(
[
'author' => $author->Title
)
]
);
}
if ($tag = $this->getCurrentTag()) {
$items[] = _t(
'Blog.FILTERDESCRIPTION_TAG',
'SilverStripe\\Blog\\Model\\Blog.FILTERDESCRIPTION_TAG',
'Tagged with {tag}',
null,
array(
[
'tag' => $tag->Title
)
]
);
}
if ($category = $this->getCurrentCategory()) {
$items[] = _t(
'Blog.FILTERDESCRIPTION_CATEGORY',
'SilverStripe\\Blog\\Model\\Blog.FILTERDESCRIPTION_CATEGORY',
'In category {category}',
null,
array(
[
'category' => $category->Title
)
]
);
}
@ -382,12 +378,12 @@ class BlogController extends PageController
}
$items[] = _t(
'Blog.FILTERDESCRIPTION_DATE',
'SilverStripe\\Blog\\Model\\Blog.FILTERDESCRIPTION_DATE',
'In {date}',
null,
array(
[
'date' => $date,
)
]
);
}
@ -496,7 +492,7 @@ class BlogController extends PageController
*/
protected function rssFeed($blogPosts, $link)
{
$rss = new RSSFeed($blogPosts, $link, $this->MetaTitle, $this->MetaDescription);
$rss = RSSFeed::create($blogPosts, $link, $this->MetaTitle, $this->MetaDescription);
$this->extend('updateRss', $rss);

View File

@ -19,8 +19,6 @@ use SilverStripe\Security\Permission;
* This class is responsible for filtering the SiteTree when necessary and also overlaps into
* filtering only published posts.
*
* @package silverstripe
* @subpackage blog
*/
class BlogFilter extends Lumberjack
{
@ -98,10 +96,10 @@ class BlogFilter extends Lumberjack
$excluded = $this->owner->getExcludedSiteTreeClassNames();
if (!empty($excluded)) {
$pages = BlogPost::get()->filter(array(
$pages = BlogPost::get()->filter([
'ParentID' => $this->owner->ID,
'ClassName' => $excluded
));
]);
$gridField = BlogFilterGridField::create(
'ChildPages',

View File

@ -5,6 +5,7 @@ namespace SilverStripe\Blog\Model;
use SilverStripe\Assets\Image;
use SilverStripe\Blog\Forms\GridField\GridFieldConfig_BlogPost;
use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Core\Manifest\ModuleLoader;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\Tab;
@ -16,32 +17,30 @@ use SilverStripe\View\Requirements;
/**
* This class is responsible for add Blog specific behaviour to Members.
*
* @package silverstripe
* @subpackage blog
*/
class BlogMemberExtension extends DataExtension
{
/**
* @var array
*/
private static $db = array(
private static $db = [
'URLSegment' => 'Varchar',
'BlogProfileSummary' => 'Text'
);
];
/**
* @var array
*/
private static $has_one = array(
private static $has_one = [
'BlogProfileImage' => Image::class
);
];
/**
* @var array
*/
private static $belongs_many_many = array(
private static $belongs_many_many = [
'BlogPosts' => BlogPost::class
);
];
/**
* {@inheritdoc}
@ -53,7 +52,7 @@ class BlogMemberExtension extends DataExtension
if ($this->owner->URLSegment && !$this->owner->isChanged('FirstName') && !$this->owner->isChanged('Surname')) {
return;
}
$this->owner->URLSegment = $this->generateURLSegment();
while (!$this->validURLSegment()) {
@ -109,15 +108,15 @@ class BlogMemberExtension extends DataExtension
$fields->removeFieldFromTab('Root', 'BlogPosts');
// Construct a better posts tab.
$module = ModuleLoader::getModule('silverstripe/blog');
Requirements::css($module->getRelativeResourcePath('css/cms.css'));
Requirements::javascript($module->getRelativeResourcePath('js/cms.js'));
Requirements::css(BLOGGER_DIR . '/css/cms.css');
Requirements::javascript(BLOGGER_DIR . '/js/cms.js');
$tab = Tab::create('BlogPosts', _t('BlogMemberExtension.TABBLOGPOSTS', 'Blog Posts'));
$tab = Tab::create('BlogPosts', _t(__CLASS__ . '.TABBLOGPOSTS', 'Blog Posts'));
$gridField = GridField::create(
'BlogPosts',
_t('BlogMemberExtension.BLOGPOSTS', 'Blog Posts'),
_t(__CLASS__ . '.BLOGPOSTS', 'Blog Posts'),
$this->owner->BlogPosts(),
GridFieldConfig_BlogPost::create()
);

View File

@ -15,8 +15,6 @@ use SilverStripe\View\Parsers\URLSegmentFilter;
/**
* An object shared by BlogTag and BlogCategory.
*
* @package silverstripe
* @subpackage blog
*/
trait BlogObject
{
@ -37,12 +35,11 @@ trait BlogObject
*/
public function getCMSFields()
{
$shortClass = ClassInfo::shortName(self::class);
$fields = TabSet::create(
'Root',
Tab::create(
'Main',
TextField::create('Title', _t($shortClass . '.Title', 'Title'))
TextField::create('Title', _t(__CLASS__ . '.Title', 'Title'))
)
);
@ -111,7 +108,7 @@ trait BlogObject
/**
* {@inheritdoc}
*/
public function canCreate($member = null, $context = array())
public function canCreate($member = null, $context = [])
{
$extended = $this->extendedCan(__FUNCTION__, $member);

View File

@ -9,6 +9,7 @@ use SilverStripe\Blog\Model\BlogCategory;
use SilverStripe\Blog\Model\BlogPostFilter;
use SilverStripe\Blog\Model\BlogTag;
use SilverStripe\Control\Controller;
use SilverStripe\Core\Manifest\ModuleLoader;
use SilverStripe\Forms\DatetimeField;
use SilverStripe\Forms\HiddenField;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
@ -22,6 +23,7 @@ use SilverStripe\ORM\UnsavedRelationList;
use SilverStripe\Security\Group;
use SilverStripe\Security\Member;
use SilverStripe\Security\Permission;
use SilverStripe\Security\Security;
use SilverStripe\TagField\TagField;
use SilverStripe\View\ArrayData;
use SilverStripe\View\Requirements;
@ -29,9 +31,6 @@ use SilverStripe\View\Requirements;
/**
* An individual blog post.
*
* @package silverstripe
* @subpackage blog
*
* @method ManyManyList Categories()
* @method ManyManyList Tags()
* @method ManyManyList Authors()
@ -59,77 +58,77 @@ class BlogPost extends Page
/**
* @var array
*/
private static $db = array(
private static $db = [
'PublishDate' => 'Datetime',
'AuthorNames' => 'Varchar(1024)',
'Summary' => 'HTMLText'
);
];
/**
* @var array
*/
private static $has_one = array(
private static $has_one = [
'FeaturedImage' => Image::class
);
];
/**
* @var array
*/
private static $owns = array(
private static $owns = [
'FeaturedImage',
);
];
/**
* @var array
*/
private static $many_many = array(
private static $many_many = [
'Categories' => BlogCategory::class,
'Tags' => BlogTag::class,
'Authors' => Member::class
);
];
/**
* @var array
*/
private static $defaults = array(
private static $defaults = [
'ShowInMenus' => false,
'InheritSideBar' => true,
'ProvideComments' => true
);
];
/**
* @var array
*/
private static $extensions = array(
private static $extensions = [
BlogPostFilter::class
);
];
/**
* @var array
*/
private static $searchable_fields = array(
private static $searchable_fields = [
'Title'
);
];
/**
* @var array
*/
private static $summary_fields = array(
private static $summary_fields = [
'Title'
);
];
/**
* @var array
*/
private static $casting = array(
private static $casting = [
'Excerpt' => 'HTMLText',
'Date' => 'DBDatetime'
);
];
/**
* @var array
*/
private static $allowed_children = array();
private static $allowed_children = [];
/**
* The default sorting lists BlogPosts with an empty PublishDate at the top.
@ -171,7 +170,7 @@ class BlogPost extends Page
}
if ($this->isAuthor($member)) {
return _t('BlogPost.AUTHOR', 'Author');
return _t(__CLASS__ . '.AUTHOR', 'Author');
}
$parent = $this->Parent();
@ -210,12 +209,13 @@ class BlogPost extends Page
*/
public function getCMSFields()
{
Requirements::css(BLOGGER_DIR . '/css/cms.css');
Requirements::javascript(BLOGGER_DIR . '/js/cms.js');
$module = ModuleLoader::getModule('silverstripe/blog');
Requirements::css($module->getRelativeResourcePath('css/cms.css'));
Requirements::javascript($module->getRelativeResourcePath('js/cms.js'));
$this->beforeUpdateCMSFields(function ($fields) {
$uploadField = UploadField::create('FeaturedImage', _t('BlogPost.FeaturedImage', 'Featured Image'));
$uploadField->getValidator()->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif'));
$uploadField = UploadField::create('FeaturedImage', _t(__CLASS__ . '.FeaturedImage', 'Featured Image'));
$uploadField->getValidator()->setAllowedExtensions(['jpg', 'jpeg', 'png', 'gif']);
/**
* @var FieldList $fields
@ -225,16 +225,16 @@ class BlogPost extends Page
$summary = HtmlEditorField::create('Summary', false);
$summary->setRows(5);
$summary->setDescription(_t(
'BlogPost.SUMMARY_DESCRIPTION',
__CLASS__ . '.SUMMARY_DESCRIPTION',
'If no summary is specified the first 30 words will be used.'
));
$summaryHolder = ToggleCompositeField::create(
'CustomSummary',
_t('BlogPost.CUSTOMSUMMARY', 'Add A Custom Summary'),
array(
_t(__CLASS__ . '.CUSTOMSUMMARY', 'Add A Custom Summary'),
[
$summary,
)
]
);
$summaryHolder->setHeadingLevel(4);
$summaryHolder->addExtraClass('custom-summary');
@ -244,25 +244,25 @@ class BlogPost extends Page
$urlSegment = $fields->dataFieldByName('URLSegment');
$urlSegment->setURLPrefix($this->Parent()->RelativeLink());
$fields->removeFieldsFromTab('Root.Main', array(
$fields->removeFieldsFromTab('Root.Main', [
'MenuTitle',
'URLSegment',
));
]);
$authorField = ListboxField::create(
'Authors',
_t('BlogPost.Authors', 'Authors'),
_t(__CLASS__ . '.Authors', 'Authors'),
$this->getCandidateAuthors()->map()->toArray()
);
$authorNames = TextField::create(
'AuthorNames',
_t('BlogPost.AdditionalCredits', 'Additional Credits'),
_t(__CLASS__ . '.AdditionalCredits', 'Additional Credits'),
null,
1024
)->setDescription(
_t(
'BlogPost.AdditionalCredits_Description',
__CLASS__ . '.AdditionalCredits_Description',
'If some authors of this post don\'t have CMS access, enter their name(s) here. You can separate multiple names with a comma.'
)
);
@ -272,12 +272,12 @@ class BlogPost extends Page
$authorNames = $authorNames->performDisabledTransformation();
}
$publishDate = DatetimeField::create('PublishDate', _t('BlogPost.PublishDate', 'Publish Date'));
$publishDate = DatetimeField::create('PublishDate', _t(__CLASS__ . '.PublishDate', 'Publish Date'));
if (!$this->PublishDate) {
$publishDate->setDescription(
_t(
'BlogPost.PublishDate_Description',
__CLASS__ . '.PublishDate_Description',
'Will be set to "now" if published without a value.'
)
);
@ -301,7 +301,7 @@ class BlogPost extends Page
$urlSegment,
TagField::create(
'Categories',
_t('BlogPost.Categories', 'Categories'),
_t(__CLASS__ . '.Categories', 'Categories'),
$categories,
$this->Categories()
)
@ -309,7 +309,7 @@ class BlogPost extends Page
->setShouldLazyLoad(true),
TagField::create(
'Tags',
_t('BlogPost.Tags', 'Tags'),
_t(__CLASS__ . '.Tags', 'Tags'),
$tags,
$this->Tags()
)
@ -338,8 +338,8 @@ class BlogPost extends Page
*/
public function getCandidateAuthors()
{
if ($this->config()->restrict_authors_to_group) {
return Group::get()->filter('Code', $this->config()->restrict_authors_to_group)->first()->Members();
if ($this->config()->get('restrict_authors_to_group')) {
return Group::get()->filter('Code', $this->config()->get('restrict_authors_to_group'))->first()->Members();
}
$list = Member::get();
@ -387,7 +387,7 @@ class BlogPost extends Page
protected function getMember($member = null)
{
if (!$member) {
$member = Member::currentUser();
$member = Security::getCurrentUser();
}
if (is_numeric($member)) {
@ -674,16 +674,16 @@ class BlogPost extends Page
// If there is no parent blog, return list undecorated
if (!$parent) {
$items = $this->Authors()->toArray();
return new ArrayList($items);
return ArrayList::create($items);
}
// Update all authors
$items = new ArrayList();
$items = ArrayList::create();
foreach ($this->Authors() as $author) {
// Add link for each author
$author = $author->customise(array(
$author = $author->customise([
'URL' => $parent->ProfileLink($author->URLSegment),
));
]);
$items->push($author);
}
@ -697,14 +697,14 @@ class BlogPost extends Page
*/
protected function getStaticCredits()
{
$items = new ArrayList();
$items = ArrayList::create();
$authors = array_filter(preg_split('/\s*,\s*/', $this->AuthorNames));
foreach ($authors as $author) {
$item = new ArrayData(array(
$item = ArrayData::create([
'Name' => $author,
));
]);
$items->push($item);
}
@ -723,7 +723,7 @@ class BlogPost extends Page
{
$labels = parent::fieldLabels($includeRelations);
$labels['Title'] = _t('BlogPost.PageTitleLabel', 'Post Title');
$labels['Title'] = _t(__CLASS__ . '.PageTitleLabel', 'Post Title');
return $labels;
}
@ -746,7 +746,7 @@ class BlogPost extends Page
{
parent::onBeforeWrite();
if (!$this->exists() && ($member = Member::currentUser())) {
if (!$this->exists() && ($member = Security::getCurrentUser())) {
$this->Authors()->add($member);
}
}

View File

@ -4,10 +4,6 @@ namespace SilverStripe\Blog\Model;
use PageController;
/**
* @package silverstripe
* @subpackage blog
*/
class BlogPostController extends PageController
{

View File

@ -17,8 +17,6 @@ use SilverStripe\Security\Permission;
* This is responsible for filtering only published posts to users who do not have permission to
* view non-published posts.
*
* @package silverstripe
* @subpackage blog
*/
class BlogPostFilter extends DataExtension
{

View File

@ -30,7 +30,7 @@ class BlogPostNotifications extends DataExtension
// If comment is spam and notification are set to not send on spam clear the recipient list
if (Config::inst()->get(__CLASS__, 'notification_on_spam') == false && $comment->IsSpam) {
$list = array();
$list = [];
}
}

View File

@ -11,8 +11,6 @@ use SilverStripe\Blog\Model\CategorisationObject;
/**
* A blog tag for keyword descriptions of a blog post.
*
* @package silverstripe
* @subpackage blog
*
* @method Blog Blog()
*
@ -42,24 +40,24 @@ class BlogTag extends DataObject implements CategorisationObject
/**
* @var array
*/
private static $db = array(
private static $db = [
'Title' => 'Varchar(255)',
'URLSegment' => 'Varchar(255)'
);
];
/**
* @var array
*/
private static $has_one = array(
private static $has_one = [
'Blog' => Blog::class
);
];
/**
* @var array
*/
private static $belongs_many_many = array(
private static $belongs_many_many = [
'BlogPosts' => BlogPost::class
);
];
/**
* {@inheritdoc}
@ -74,6 +72,6 @@ class BlogTag extends DataObject implements CategorisationObject
*/
protected function getDuplicateError()
{
return _t('BlogTag.Duplicate', 'A blog tag already exists with that name.');
return _t(__CLASS__ . '.Duplicate', 'A blog tag already exists with that name.');
}
}

View File

@ -38,24 +38,24 @@ class BlogArchiveWidget extends Widget
/**
* @var array
*/
private static $db = array(
private static $db = [
'NumberToDisplay' => 'Int',
'ArchiveType' => 'Enum(\'Monthly,Yearly\', \'Monthly\')',
);
];
/**
* @var array
*/
private static $defaults = array(
private static $defaults = [
'NumberOfMonths' => 12,
);
];
/**
* @var array
*/
private static $has_one = array(
private static $has_one = [
'Blog' => Blog::class,
);
];
/**
* {@inheritdoc}
@ -71,21 +71,21 @@ class BlogArchiveWidget extends Widget
$type = $archiveType->enumValues();
foreach ($type as $k => $v) {
$type[$k] = _t('BlogArchiveWidget.' . ucfirst(strtolower($v)), $v);
$type[$k] = _t(__CLASS__ .'.' . ucfirst(strtolower($v)), $v);
}
/**
* @var FieldList $fields
*/
$fields->merge(array(
$fields->merge([
DropdownField::create(
'BlogID',
_t('BlogArchiveWidget.Blog', 'Blog'),
_t(__CLASS__ . '.Blog', 'Blog'),
Blog::get()->map()
),
DropdownField::create('ArchiveType', _t('BlogArchiveWidget.ArchiveType', 'ArchiveType'), $type),
NumericField::create('NumberToDisplay', _t('BlogArchiveWidget.NumberToDisplay', 'No. to Display'))
));
DropdownField::create('ArchiveType', _t(__CLASS__ . '.ArchiveType', 'ArchiveType'), $type),
NumericField::create('NumberToDisplay', _t(__CLASS__ . '.NumberToDisplay', 'No. to Display'))
]);
});
return parent::getCMSFields();
@ -112,7 +112,7 @@ class BlogArchiveWidget extends Widget
$posts = $posts->limit($this->NumberToDisplay);
}
$archive = new ArrayList();
$archive = ArrayList::create();
if ($posts->count() > 0) {
foreach ($posts as $post) {
@ -132,10 +132,10 @@ class BlogArchiveWidget extends Widget
$title = $date->FormatI18N("%B %Y");
}
$archive->push(new ArrayData(array(
$archive->push(ArrayData::create([
'Title' => $title,
'Link' => Controller::join_links($this->Blog()->Link('archive'), $year, $month)
)));
]));
}
}

View File

@ -11,6 +11,7 @@ use SilverStripe\Core\Convert;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\NumericField;
use SilverStripe\ORM\DataList;
use SilverStripe\Widgets\Model\Widget;
/**
@ -36,18 +37,18 @@ class BlogCategoriesWidget extends Widget
/**
* @var array
*/
private static $db = array(
private static $db = [
'Limit' => 'Int',
'Order' => 'Varchar',
'Direction' => 'Varchar',
);
];
/**
* @var array
*/
private static $has_one = array(
private static $has_one = [
'Blog' => Blog::class,
);
];
/**
* {@inheritdoc}
@ -57,18 +58,18 @@ class BlogCategoriesWidget extends Widget
$this->beforeUpdateCMSFields(function (FieldList $fields) {
$fields[] = DropdownField::create(
'BlogID',
_t('BlogCategoriesWidget.Blog', 'Blog'),
_t(__CLASS__ . '.Blog', 'Blog'),
Blog::get()->map()
);
$fields[] = NumericField::create(
'Limit',
_t('BlogCategoriesWidget.Limit', 'Limit'),
_t(__CLASS__ . '.Limit', 'Limit'),
0
)
->setDescription(
_t(
'BlogCategoriesWidget.Limit_Description',
__CLASS__ . '.Limit_Description',
'Limit the number of categories shown by this widget (set to 0 to show all categories).'
)
)
@ -76,21 +77,21 @@ class BlogCategoriesWidget extends Widget
$fields[] = DropdownField::create(
'Order',
_t('BlogCategoriesWidget.Sort', 'Sort'),
array('Title' => 'Title', 'Created' => 'Created', 'LastEdited' => 'Updated')
_t(__CLASS__ . '.Sort', 'Sort'),
['Title' => 'Title', 'Created' => 'Created', 'LastEdited' => 'Updated']
)
->setDescription(
_t('BlogCategoriesWidget.Sort_Description', 'Change the order of categories shown by this widget.')
_t(__CLASS__ . '.Sort_Description', 'Change the order of categories shown by this widget.')
);
$fields[] = DropdownField::create(
'Direction',
_t('BlogCategoriesWidget.Direction', 'Direction'),
array('ASC' => 'Ascending', 'DESC' => 'Descending')
_t(__CLASS__ . '.Direction', 'Direction'),
['ASC' => 'Ascending', 'DESC' => 'Descending']
)
->setDescription(
_t(
'BlogCategoriesWidget.Direction_Description',
__CLASS__ . '.Direction_Description',
'Change the direction of ordering of categories shown by this widget.'
)
);
@ -107,7 +108,7 @@ class BlogCategoriesWidget extends Widget
$blog = $this->Blog();
if (!$blog) {
return array();
return [];
}
$query = $blog->Categories();

View File

@ -36,16 +36,16 @@ class BlogRecentPostsWidget extends Widget
/**
* @var array
*/
private static $db = array(
private static $db = [
'NumberOfPosts' => 'Int',
);
];
/**
* @var array
*/
private static $has_one = array(
private static $has_one = [
'Blog' => Blog::class,
);
];
/**
* {@inheritdoc}
@ -56,10 +56,10 @@ class BlogRecentPostsWidget extends Widget
/**
* @var FieldList $fields
*/
$fields->merge(array(
DropdownField::create('BlogID', _t('BlogRecentPostsWidget.Blog', 'Blog'), Blog::get()->map()),
NumericField::create('NumberOfPosts', _t('BlogRecentPostsWidget.NumberOfPosts', 'Number of Posts'))
));
$fields->merge([
DropdownField::create('BlogID', _t(__CLASS__ . '.Blog', 'Blog'), Blog::get()->map()),
NumericField::create('NumberOfPosts', _t(__CLASS__ . '.NumberOfPosts', 'Number of Posts'))
]);
});
return parent::getCMSFields();
@ -78,6 +78,6 @@ class BlogRecentPostsWidget extends Widget
->limit($this->NumberOfPosts);
}
return array();
return [];
}
}

View File

@ -37,14 +37,14 @@ class BlogTagsCloudWidget extends Widget
/**
* @var array
*/
private static $db = array();
private static $db = [];
/**
* @var array
*/
private static $has_one = array(
private static $has_one = [
'Blog' => Blog::class,
);
];
/**
* {@inheritdoc}
@ -58,7 +58,7 @@ class BlogTagsCloudWidget extends Widget
$fields->push(
DropdownField::create(
'BlogID',
_t('BlogTagsCloudWidget.Blog', 'Blog'),
_t(__CLASS__ . '.Blog', 'Blog'),
Blog::get()->map()
)
);
@ -89,9 +89,9 @@ class BlogTagsCloudWidget extends Widget
$maxTagCount = 0;
// create DataObjects that can be used to render the tag cloud
$tags = new ArrayList();
$tags = ArrayList::create();
foreach ($records as $record) {
$tag = new DataObject();
$tag = DataObject::create();
$tag->TagName = $record['Title'];
$link = $bloglink.'tag/'.$record['URLSegment'];
$tag->Link = $link;
@ -115,6 +115,6 @@ class BlogTagsCloudWidget extends Widget
return $tags;
}
return array();
return [];
}
}

View File

@ -36,18 +36,18 @@ class BlogTagsWidget extends Widget
/**
* @var array
*/
private static $db = array(
private static $db = [
'Limit' => 'Int',
'Order' => 'Varchar',
'Direction' => 'Varchar',
);
];
/**
* @var array
*/
private static $has_one = array(
private static $has_one = [
'Blog' => Blog::class
);
];
/**
* {@inheritdoc}
@ -57,18 +57,18 @@ class BlogTagsWidget extends Widget
$this->beforeUpdateCMSFields(function (Fieldlist $fields) {
$fields[] = DropdownField::create(
'BlogID',
_t('BlogTagsWidget.Blog', 'Blog'),
_t(__CLASS__ . '.Blog', 'Blog'),
Blog::get()->map()
);
$fields[] = NumericField::create(
'Limit',
_t('BlogTagsWidget.Limit', 'Limit'),
_t(__CLASS__ . '.Limit', 'Limit'),
0
)
->setDescription(
_t(
'BlogTagsWidget.Limit_Description',
__CLASS__ . '.Limit_Description',
'Limit the number of tags shown by this widget (set to 0 to show all tags).'
)
)
@ -76,21 +76,21 @@ class BlogTagsWidget extends Widget
$fields[] = DropdownField::create(
'Order',
_t('BlogTagsWidget.Sort', 'Sort'),
array('Title' => 'Title', 'Created' => 'Created', 'LastEdited' => 'Updated')
_t(__CLASS__ . '.Sort', 'Sort'),
['Title' => 'Title', 'Created' => 'Created', 'LastEdited' => 'Updated']
)
->setDescription(
_t('BlogTagsWidget.Sort_Description', 'Change the order of tags shown by this widget.')
_t(__CLASS__ . '.Sort_Description', 'Change the order of tags shown by this widget.')
);
$fields[] = DropdownField::create(
'Direction',
_t('BlogTagsWidget.Direction', 'Direction'),
array('ASC' => 'Ascending', 'DESC' => 'Descending')
_t(__CLASS__ . '.Direction', 'Direction'),
['ASC' => 'Ascending', 'DESC' => 'Descending']
)
->setDescription(
_t(
'BlogTagsWidget.Direction_Description',
__CLASS__ . '.Direction_Description',
'Change the direction of ordering of tags shown by this widget.'
)
);
@ -107,7 +107,7 @@ class BlogTagsWidget extends Widget
$blog = $this->Blog();
if (!$blog) {
return array();
return [];
}
$query = $blog->Tags();

View File

@ -11,6 +11,7 @@ use SilverStripe\Dev\FunctionalTest;
use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\ORM\ValidationException;
use SilverStripe\Security\Member;
use SilverStripe\Security\Security;
/**
* @mixin PHPUnit_Framework_TestCase
@ -48,10 +49,10 @@ class BlogCategoryTest extends FunctionalTest
*/
public function testBlogPosts()
{
$member = Member::currentUser();
$member = Security::getCurrentUser();
if ($member) {
$member->logout();
Security::setCurrentUser(null);
}
$this->objFromFixture(BlogPost::class, 'FirstBlogPost');

View File

@ -6,6 +6,7 @@ use SilverStripe\Blog\Model\Blog;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\Security\Member;
use SilverStripe\Security\Security;
/**
* @mixin PHPUnit_Framework_TestCase
@ -38,10 +39,10 @@ class BlogPostFilterTest extends SapphireTest
*/
public function testFilter()
{
$member = Member::currentUser();
$member = Security::getCurrentUser();
if ($member) {
$member->logout();
Security::setCurrentUser(null);
}
/**

View File

@ -27,14 +27,14 @@ class BlogPostNotificationsTest extends SapphireTest
$comment
)->toArray();
$segments = array();
$segments = [];
foreach ($recipients as $recipient) {
array_push($segments, $recipient->URLSegment);
}
sort($segments);
$this->assertEquals(
array('blog-contributor', 'blog-editor', 'blog-writer'),
['blog-contributor', 'blog-editor', 'blog-writer'],
$segments
);
}

View File

@ -43,33 +43,33 @@ class BlogPostTest extends SapphireTest
{
$someFutureDate = '2013-10-10 20:00:00';
$somePastDate = '2009-10-10 20:00:00';
return array(
return [
// Check this post given the date has passed
array($someFutureDate, 'Editor', 'PostA', true),
array($someFutureDate, 'Contributor', 'PostA', true),
array($someFutureDate, 'BlogEditor', 'PostA', true),
array($someFutureDate, 'Writer', 'PostA', true),
[$someFutureDate, 'Editor', 'PostA', true],
[$someFutureDate, 'Contributor', 'PostA', true],
[$someFutureDate, 'BlogEditor', 'PostA', true],
[$someFutureDate, 'Writer', 'PostA', true],
// Check unpublished pages
array($somePastDate, 'Editor', 'PostA', true),
array($somePastDate, 'Contributor', 'PostA', true),
array($somePastDate, 'BlogEditor', 'PostA', true),
array($somePastDate, 'Writer', 'PostA', true),
[$somePastDate, 'Editor', 'PostA', true],
[$somePastDate, 'Contributor', 'PostA', true],
[$somePastDate, 'BlogEditor', 'PostA', true],
[$somePastDate, 'Writer', 'PostA', true],
// Test a page that was authored by another user
// Check this post given the date has passed
array($someFutureDate, 'Editor', 'FirstBlogPost', true),
array($someFutureDate, 'Contributor', 'FirstBlogPost', true),
array($someFutureDate, 'BlogEditor', 'FirstBlogPost', true),
array($someFutureDate, 'Writer', 'FirstBlogPost', true),
[$someFutureDate, 'Editor', 'FirstBlogPost', true],
[$someFutureDate, 'Contributor', 'FirstBlogPost', true],
[$someFutureDate, 'BlogEditor', 'FirstBlogPost', true],
[$someFutureDate, 'Writer', 'FirstBlogPost', true],
// Check future pages - non-editors shouldn't be able to see this
array($somePastDate, 'Editor', 'FirstBlogPost', true),
array($somePastDate, 'Contributor', 'FirstBlogPost', false),
array($somePastDate, 'BlogEditor', 'FirstBlogPost', false),
array($somePastDate, 'Writer', 'FirstBlogPost', false),
);
[$somePastDate, 'Editor', 'FirstBlogPost', true],
[$somePastDate, 'Contributor', 'FirstBlogPost', false],
[$somePastDate, 'BlogEditor', 'FirstBlogPost', false],
[$somePastDate, 'Writer', 'FirstBlogPost', false],
];
}
public function testCandidateAuthors()

View File

@ -10,6 +10,7 @@ use SilverStripe\Dev\FunctionalTest;
use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\ORM\ValidationException;
use SilverStripe\Security\Member;
use SilverStripe\Security\Security;
/**
* @mixin PHPUnit_Framework_TestCase
@ -48,10 +49,10 @@ class BlogTagTest extends FunctionalTest
*/
public function testBlogPosts()
{
$member = Member::currentUser();
$member = Security::getCurrentUser();
if ($member) {
$member->logout();
Security::setCurrentUser(null);
}
$this->objFromFixture(BlogPost::class, 'FirstBlogPost');

View File

@ -23,12 +23,12 @@ class BlogTagsCloudWidgetTest extends SapphireTest
$widget = new BlogTagsCloudWidget();
$fields = $widget->getCMSFields();
$names = array();
$names = [];
foreach ($fields as $field) {
array_push($names, $field->getName());
}
$expected = array('Title', 'Enabled', 'BlogID');
$expected = ['Title', 'Enabled', 'BlogID'];
$this->assertEquals($expected, $names);
}

View File

@ -16,6 +16,7 @@ use SilverStripe\ORM\DataModel;
use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\ORM\SS_List;
use SilverStripe\Security\Member;
use SilverStripe\Security\Security;
/**
* @mixin PHPUnit_Framework_TestCase
@ -58,10 +59,10 @@ class BlogTest extends SapphireTest
public function testGetExcludedSiteTreeClassNames()
{
$member = Member::currentUser();
$member = Security::getCurrentUser();
if ($member) {
$member->logout();
Security::setCurrentUser(null);
}
/**
@ -82,10 +83,10 @@ class BlogTest extends SapphireTest
public function testGetArchivedBlogPosts()
{
$member = Member::currentUser();
$member = Security::getCurrentUser();
if ($member) {
$member->logout();
Security::setCurrentUser(null);
}
/**
@ -324,7 +325,7 @@ class BlogTest extends SapphireTest
// Request first tag
$this->requestURL($controller, 'first-post/tag/first-tag');
$this->assertIDsEquals(
array($firstPostID, $firstFuturePostID, $secondFuturePostID),
[$firstPostID, $firstFuturePostID, $secondFuturePostID],
$controller->PaginatedList()
);
}
@ -342,7 +343,7 @@ class BlogTest extends SapphireTest
// Request 2013 posts
$this->requestURL($controller, 'first-post/archive/2013');
$this->assertIDsEquals(
array($firstPostID, $secondPostID, $secondFuturePostID),
[$firstPostID, $secondPostID, $secondFuturePostID],
$controller->PaginatedList()
);
}