From c1cb8576b3a9713cbfeef2ec2aff3e3bf862cda2 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Fri, 13 Jan 2017 15:33:53 +1300 Subject: [PATCH] FIX Validation of existing tags, duplicated GridField add button, formatting in categorisation, bootstrapify buttons --- css/cms.css | 6 + js/gridfieldaddbydbfield.js | 6 +- lang/en.yml | 2 +- scss/cms.scss | 255 +++++++++--------- src/Admin/GridFieldCategorisationConfig.php | 2 +- src/Forms/GridField/GridFieldAddByDBField.php | 22 +- src/Model/Blog.php | 4 +- src/Model/BlogController.php | 4 +- src/Model/BlogObject.php | 34 +-- src/Model/BlogPost.php | 4 +- src/Model/BlogPostController.php | 4 +- src/Model/BlogTag.php | 2 +- 12 files changed, 179 insertions(+), 166 deletions(-) diff --git a/css/cms.css b/css/cms.css index 2998d91..7aa1caf 100755 --- a/css/cms.css +++ b/css/cms.css @@ -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; } diff --git a/js/gridfieldaddbydbfield.js b/js/gridfieldaddbydbfield.js index f6d31e2..67799f3 100644 --- a/js/gridfieldaddbydbfield.js +++ b/js/gridfieldaddbydbfield.js @@ -1,20 +1,16 @@ (function ($) { - $.entwine('ss', function ($) { - /** * Prevent the CMS hijacking the return key */ $('.add-existing-autocompleter input.text').entwine({ 'onkeydown': function (e) { - if(e.which == 13) { + if (e.which == 13) { $parent = $(this).parents('.add-existing-autocompleter'); $parent.find('button[type="submit"]').click(); return false; } } }); - }); - })(jQuery); diff --git a/lang/en.yml b/lang/en.yml index 9ba7ddd..afffaf8 100755 --- a/lang/en.yml +++ b/lang/en.yml @@ -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 diff --git a/scss/cms.scss b/scss/cms.scss index 670f2d4..c2a813e 100755 --- a/scss/cms.scss +++ b/scss/cms.scss @@ -17,185 +17,192 @@ } #FeaturedImage .middleColumn { - clear: none; - float: left; + clear: none; + float: left; } .has-panel .cms-content-tools.blog-admin-sidebar { - width: 280px; - border-right: none; - border-left: 1px solid #C0C0C2; - position: absolute !important; /* overrides cms !imporant style */ - right: 0px; + width: 280px; + border-right: none; + border-left: 1px solid #C0C0C2; + position: absolute !important; /* overrides cms !imporant style */ + right: 0px; top: 0; - height: 100%; + height: 100%; - .cms-panel-toggle a { - text-align: left; + .cms-panel-toggle a { + text-align: left; margin: 0; - } + } .cms-panel-toggle.south { border-top: 1px solid #aaaaaa; } - ~ .blog-admin-outer { - width: 100%; - padding-right: 280px; - position: absolute; - height: 100%; - overflow-y: hidden; - overflow-x: hidden; - box-sizing: border-box; + ~ .blog-admin-outer { + width: 100%; + padding-right: 280px; + position: absolute; + height: 100%; + overflow-y: hidden; + overflow-x: hidden; + box-sizing: border-box; - > .ss-tabset { - position: relative; - overflow: auto; - height: 100%; - width: 100%; + > .ss-tabset { + position: relative; + overflow: auto; + height: 100%; + width: 100%; - #Title { - label { - float: none; - } - .middleColumn, input { - width: 100%; - max-width: 100%; - margin-left: 0; - } - } - } - } + #Title { + label { + float: none; + } + .middleColumn, input { + width: 100%; + max-width: 100%; + margin-left: 0; + } + } + } + } - .cms-content-view { - > .field { - + .field { - margin-top: 10px; - } + .cms-content-view { + > .field { + + .field { + margin-top: 10px; + } - &.urlsegment { - .preview { - padding-top: 0; - line-height: 25px; - } + &.urlsegment { + .preview { + padding-top: 0; + line-height: 25px; + } - .edit { - float: right; - } - } + .edit { + float: right; + } + } - &.datetime { - > .middleColumn { - > .date { - width: 60%; - } + &.datetime { + > .middleColumn { + > .date { + width: 60%; + } - > .time { - width: 36%; - float: right; - } + > .time { + width: 36%; + float: right; + } - .middleColumn, input { - width: 100%; - } - } - } - } - } + .middleColumn, input { + width: 100%; + } + } + } + } + } - &.collapsed { - ~ .blog-admin-outer { - padding-right: 41px; + &.collapsed { + ~ .blog-admin-outer { + padding-right: 41px; #Root_Main { margin-right: 15px; } - } + } - } + } - &.cms-content-tools { - .cms-panel-content { - width: auto; - } - } + &.cms-content-tools { + .cms-panel-content { + width: auto; + } + } } .toggle-description { - text-indent: -1000000px; - display: inline-block; - background: url("../images/information.png") no-repeat center center; - width: 20px; - height: 20px; - margin-left: 4px; + text-indent: -1000000px; + display: inline-block; + background: url("../images/information.png") no-repeat center center; + width: 20px; + height: 20px; + margin-left: 4px; } .middleColumn.toggle-description-correct-middle { - margin-left: 0; - float: left; - width: 416px; + margin-left: 0; + float: left; + width: 416px; } label.right.toggle-description-correct-right { - display: inline-block; - margin-left: 0; - clear: none; - float: left; + display: inline-block; + margin-left: 0; + clear: none; + float: left; } .description.toggle-description-correct-description { - width: 416px; - padding: 12px 0; + width: 416px; + padding: 12px 0; } .custom-summary { - .ui-accordion-content .field { - margin: 0; - } + .ui-accordion-content .field { + margin: 0; + } - .ui-accordion-content, - .ui-accordion-content .field { - padding: 0; - } + .ui-accordion-content, + .ui-accordion-content .field { + padding: 0; + } - .ui-icon-triangle-1-e { - background-position: -16px -128px; - } + .ui-icon-triangle-1-e { + background-position: -16px -128px; + } } .cms table.ss-gridfield-table { - tr td.MergeAction { - width: 225px; + tr td.MergeAction { + width: 225px; - a { - display: block; - height: 100%; - width: 100%; - } + a { + display: block; + height: 100%; + width: 100%; + } - select { - width: 150px; - } - } + select { + width: 150px; + } + } } .cms-content-actions, .cms-preview-controls { - z-index: 999; + z-index: 999; } .blog-cms-categorisation { + .MergeActionReveal { + margin-left: 10px; + } - .MergeActionReveal { - margin-left: 10px; - } + .toolbar--content { + margin-top: 0; + } - .MergeActionReveal:after { - content: ''; - background: url('../images/move-icon.png'); - display: inline-block; - height: 16px; - width: 16px; - margin-left: 4px; - } + .MergeActionReveal:after { + content: ''; + background: url('../images/move-icon.png'); + display: inline-block; + height: 16px; + width: 16px; + margin-left: 4px; + } + + button.action { + margin-left: 5px; + } } diff --git a/src/Admin/GridFieldCategorisationConfig.php b/src/Admin/GridFieldCategorisationConfig.php index 6455903..697b0f8 100644 --- a/src/Admin/GridFieldCategorisationConfig.php +++ b/src/Admin/GridFieldCategorisationConfig.php @@ -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') diff --git a/src/Forms/GridField/GridFieldAddByDBField.php b/src/Forms/GridField/GridFieldAddByDBField.php index 18c5b47..2cd46c8 100644 --- a/src/Forms/GridField/GridFieldAddByDBField.php +++ b/src/Forms/GridField/GridFieldAddByDBField.php @@ -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' + ) ); } } diff --git a/src/Model/Blog.php b/src/Model/Blog.php index 15bae2d..2b12b2d 100644 --- a/src/Model/Blog.php +++ b/src/Model/Blog.php @@ -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) { diff --git a/src/Model/BlogController.php b/src/Model/BlogController.php index 3dc2d26..e9688ab 100644 --- a/src/Model/BlogController.php +++ b/src/Model/BlogController.php @@ -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 diff --git a/src/Model/BlogObject.php b/src/Model/BlogObject.php index 419def1..2500084 100644 --- a/src/Model/BlogObject.php +++ b/src/Model/BlogObject.php @@ -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; diff --git a/src/Model/BlogPost.php b/src/Model/BlogPost.php index 03aa95b..4499502 100644 --- a/src/Model/BlogPost.php +++ b/src/Model/BlogPost.php @@ -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()); diff --git a/src/Model/BlogPostController.php b/src/Model/BlogPostController.php index 9891372..2b09699 100644 --- a/src/Model/BlogPostController.php +++ b/src/Model/BlogPostController.php @@ -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 { } diff --git a/src/Model/BlogTag.php b/src/Model/BlogTag.php index fc96537..9e65e1e 100644 --- a/src/Model/BlogTag.php +++ b/src/Model/BlogTag.php @@ -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.'); } }