FIX Validation of existing tags, duplicated GridField add button, formatting in categorisation, bootstrapify buttons

This commit is contained in:
Robbie Averill 2017-01-13 15:33:53 +13:00
parent 5f07a3cc23
commit c1cb8576b3
12 changed files with 179 additions and 166 deletions

View File

@ -117,6 +117,9 @@ label.right.toggle-description-correct-right {
.blog-cms-categorisation .MergeActionReveal {
margin-left: 10px; }
.blog-cms-categorisation .toolbar--content {
margin-top: 0; }
.blog-cms-categorisation .MergeActionReveal:after {
content: '';
background: url("../images/move-icon.png");
@ -124,3 +127,6 @@ label.right.toggle-description-correct-right {
height: 16px;
width: 16px;
margin-left: 4px; }
.blog-cms-categorisation button.action {
margin-left: 5px; }

View File

@ -1,7 +1,5 @@
(function ($) {
$.entwine('ss', function ($) {
/**
* Prevent the CMS hijacking the return key
*/
@ -14,7 +12,5 @@
}
}
});
});
})(jQuery);

View File

@ -87,7 +87,7 @@ en:
PLURALNAME: 'Blog Recent Posts Widgets'
SINGULARNAME: 'Blog Recent Posts Widget'
BlogTag:
Duplicate: 'A blog tags already exists with that name'
Duplicate: 'A blog tag already exists with that name'
PLURALNAME: 'Blog Tags'
SINGULARNAME: 'Blog Tag'
Title: Title

View File

@ -185,11 +185,14 @@ label.right.toggle-description-correct-right {
}
.blog-cms-categorisation {
.MergeActionReveal {
margin-left: 10px;
}
.toolbar--content {
margin-top: 0;
}
.MergeActionReveal:after {
content: '';
background: url('../images/move-icon.png');
@ -198,4 +201,8 @@ label.right.toggle-description-correct-right {
width: 16px;
margin-left: 4px;
}
button.action {
margin-left: 5px;
}
}

View File

@ -20,7 +20,7 @@ class GridFieldCategorisationConfig extends GridFieldConfig_RecordEditor
{
parent::__construct($itemsPerPage);
$this->removeComponentsByType('GridFieldAddNewButton');
$this->removeComponentsByType('SilverStripe\\Forms\\GridField\\GridFieldAddNewButton');
$this->addComponent(
new GridFieldAddByDBField('buttons-before-left')

View File

@ -94,7 +94,7 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
if ($obj->canCreate()) {
$id = $gridField->getList()->add($obj);
if (!$id) {
$gridField->setError(
$gridField->setCustomValidationMessage(
_t(
'GridFieldAddByDBField.AddFail',
'Unable to save {class} to the database.',
@ -102,8 +102,7 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
array(
'class' => get_class($obj),
)
),
'error'
)
);
}
} else {
@ -174,7 +173,7 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
$obj = singleton($dataClass);
if (!$obj->canCreate()) {
return "";
return '';
}
$dbField = $this->getDataObjectField();
@ -192,16 +191,17 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
$addAction = new GridField_FormAction(
$gridField,
'add',
_t('GridFieldAddByDBField.Add',
'Add {name}', "Add button text",
array(
'name' => $obj->i18n_singular_name(),
)
_t(
'GridFieldAddByDBField.Add',
'Add {name}',
'Add button text',
['name' => $obj->i18n_singular_name()]
),
'add',
'add'
);
$addAction->setAttribute('data-icon', 'add');
$addAction->addExtraClass('btn btn-primary');
$forTemplate = new ArrayData(array());
@ -210,7 +210,9 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
$forTemplate->Fields->push($addAction);
return array(
$this->targetFragment => $forTemplate->renderWith('SilverStripe\\Blog\\Forms\\GridField\\GridFieldAddByDBField')
$this->targetFragment => $forTemplate->renderWith(
'SilverStripe\\Blog\\Forms\\GridField\\GridFieldAddByDBField'
)
);
}
}

View File

@ -3,7 +3,7 @@
namespace SilverStripe\Blog\Model;
use Page;
use Page_Controller;
use PageController;
use SilverStripe\Blog\Admin\GridFieldCategorisationConfig;
use SilverStripe\Blog\Forms\GridField\GridFieldConfig_BlogPost;
use SilverStripe\CMS\Controllers\RootURLController;
@ -272,7 +272,7 @@ class Blog extends Page implements PermissionProvider
public function RoleOf($member)
{
if (is_numeric($member)) {
$member = DataObject::get_by_id(Member::class, $member);
$member = Member::get()->byId($member);
}
if (!$member) {

View File

@ -2,7 +2,7 @@
namespace SilverStripe\Blog\Model;
use Page_Controller;
use PageController;
use SilverStripe\Control\RSS\RSSFeed;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\FieldType\DBDatetime;
@ -13,7 +13,7 @@ use SilverStripe\Security\Member;
* @package silverstripe
* @subpackage blog
*/
class BlogController extends Page_Controller
class BlogController extends PageController
{
/**
* @var array

View File

@ -36,8 +36,10 @@ trait BlogObject
*/
public function getCMSFields()
{
$fields = TabSet::create('Root',
Tab::create('Main',
$fields = TabSet::create(
'Root',
Tab::create(
'Main',
TextField::create('Title', _t(self::class . '.Title', 'Title'))
)
);
@ -65,9 +67,10 @@ trait BlogObject
return $validation;
}
if ($this->getDuplicatesByUrlSegment()->count() > 0) {
if ($this->getDuplicatesByField('Title')->count() > 0) {
$validation->addError($this->getDuplicateError(), self::DUPLICATE_EXCEPTION);
}
return $validation;
}
@ -134,7 +137,7 @@ trait BlogObject
return $extended;
}
return $this->Blog()->canEdit($member);
return $this->Blog()->canDelete($member);
}
/**
@ -178,36 +181,37 @@ trait BlogObject
$increment = (int) $increment;
$filter = URLSegmentFilter::create();
$this->URLSegment = $filter->filter($this->owner->Title);
$this->URLSegment = $filter->filter($this->Title);
if ($increment > 0) {
$this->URLSegment .= '-' . $increment;
}
if ($this->getDuplicatesByUrlSegment()->count() > 0) {
$this->owner->generateURLSegment($increment + 1);
if ($this->getDuplicatesByField('URLSegment')->count() > 0) {
$this->generateURLSegment($increment + 1);
}
return $this->owner->URLSegment;
return $this->URLSegment;
}
/**
* Looks for objects of the same type by url segment.
* Looks for objects o the same type and the same value by the given Field
*
* @param string $field E.g. URLSegment or Title
* @return DataList
*/
protected function getDuplicatesByUrlSegment()
protected function getDuplicatesByField($field)
{
$duplicates = DataList::create(self::class)
->filter(
array(
'URLSegment' => $this->URLSegment,
'BlogID' => (int) $this->BlogID,
)
[
$field => $this->$field,
'BlogID' => (int) $this->BlogID
]
);
if ($this->ID) {
$duplicates = $duplicates->exclude('ID', $this->ID);
$duplicates->exclude('ID', $this->ID);
}
return $duplicates;

View File

@ -74,7 +74,7 @@ class BlogPost extends Page
private static $many_many = array(
'Categories' => 'SilverStripe\\Blog\\Model\\BlogCategory',
'Tags' => 'SilverStripe\\Blog\\Model\\BlogTag',
'Authors' => 'SilverStripe\\Security\\Member'
'Authors' => Member::class
);
/**
@ -230,8 +230,6 @@ class BlogPost extends Page
$fields->insertAfter($summaryHolder, 'FeaturedImage');
$fields->push(HiddenField::create('MenuTitle'));
$urlSegment = $fields->dataFieldByName('URLSegment');
$urlSegment->setURLPrefix($this->Parent()->RelativeLink());

View File

@ -2,13 +2,13 @@
namespace SilverStripe\Blog\Model;
use Page_Controller;
use PageController;
/**
* @package silverstripe
* @subpackage blog
*/
class BlogPostController extends Page_Controller
class BlogPostController extends PageController
{
}

View File

@ -72,6 +72,6 @@ class BlogTag extends DataObject implements CategorisationObject
*/
protected function getDuplicateError()
{
return _t('BlogTag.Duplicate', 'A blog tags already exists with that name.');
return _t('BlogTag.Duplicate', 'A blog tag already exists with that name.');
}
}