mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
FIX Update CMS fields now that they're being scaffolded (#775)
This commit is contained in:
parent
c4885ce67b
commit
301c45b217
@ -129,6 +129,17 @@ class Blog extends Page implements PermissionProvider
|
|||||||
'PostsPerPage' => 10
|
'PostsPerPage' => 10
|
||||||
];
|
];
|
||||||
|
|
||||||
|
private static array $scaffold_cms_fields_settings = [
|
||||||
|
'ignoreFields' => [
|
||||||
|
'PostsPerPage',
|
||||||
|
],
|
||||||
|
'ignoreRelations' => [
|
||||||
|
'Editors',
|
||||||
|
'Writers',
|
||||||
|
'Contributors',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
|
@ -3,13 +3,9 @@
|
|||||||
namespace SilverStripe\Blog\Model;
|
namespace SilverStripe\Blog\Model;
|
||||||
|
|
||||||
use Page;
|
use Page;
|
||||||
use SilverStripe\AssetAdmin\Forms\UploadField;
|
|
||||||
use SilverStripe\Assets\Image;
|
use SilverStripe\Assets\Image;
|
||||||
use SilverStripe\Control\Controller;
|
use SilverStripe\Control\Controller;
|
||||||
use SilverStripe\Core\Config\Config;
|
use SilverStripe\Core\Config\Config;
|
||||||
use SilverStripe\Forms\DatetimeField;
|
|
||||||
use SilverStripe\Forms\FieldList;
|
|
||||||
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
|
|
||||||
use SilverStripe\Forms\ListboxField;
|
use SilverStripe\Forms\ListboxField;
|
||||||
use SilverStripe\Forms\TextField;
|
use SilverStripe\Forms\TextField;
|
||||||
use SilverStripe\Forms\ToggleCompositeField;
|
use SilverStripe\Forms\ToggleCompositeField;
|
||||||
@ -23,7 +19,6 @@ use SilverStripe\Security\Group;
|
|||||||
use SilverStripe\Security\Member;
|
use SilverStripe\Security\Member;
|
||||||
use SilverStripe\Security\Permission;
|
use SilverStripe\Security\Permission;
|
||||||
use SilverStripe\Security\Security;
|
use SilverStripe\Security\Security;
|
||||||
use SilverStripe\TagField\TagField;
|
|
||||||
use SilverStripe\Versioned\Versioned;
|
use SilverStripe\Versioned\Versioned;
|
||||||
use SilverStripe\View\ArrayData;
|
use SilverStripe\View\ArrayData;
|
||||||
use SilverStripe\View\Requirements;
|
use SilverStripe\View\Requirements;
|
||||||
@ -100,6 +95,15 @@ class BlogPost extends Page
|
|||||||
'Authors' => Member::class
|
'Authors' => Member::class
|
||||||
];
|
];
|
||||||
|
|
||||||
|
private static array $scaffold_cms_fields_settings = [
|
||||||
|
'ignoreFields' => [
|
||||||
|
'AuthorNames',
|
||||||
|
],
|
||||||
|
'ignoreRelations' => [
|
||||||
|
'Authors',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The ProvideComments db column is defined in the silverstripe/comments module
|
* The ProvideComments db column is defined in the silverstripe/comments module
|
||||||
* The InheritSideBar db column is defined in the silverstripe/widgets module
|
* The InheritSideBar db column is defined in the silverstripe/widgets module
|
||||||
@ -252,42 +256,40 @@ class BlogPost extends Page
|
|||||||
Requirements::javascript('silverstripe/blog:client/dist/js/main.bundle.js');
|
Requirements::javascript('silverstripe/blog:client/dist/js/main.bundle.js');
|
||||||
|
|
||||||
$this->beforeUpdateCMSFields(function ($fields) {
|
$this->beforeUpdateCMSFields(function ($fields) {
|
||||||
$uploadField = UploadField::create('FeaturedImage', _t(__CLASS__ . '.FeaturedImage', 'Featured Image'));
|
$uploadField = $fields->dataFieldByName('FeaturedImage');
|
||||||
$uploadField->getValidator()->setAllowedExtensions(['jpg', 'jpeg', 'png', 'gif']);
|
$uploadField?->getValidator()->setAllowedExtensions(['jpg', 'jpeg', 'png', 'gif']);
|
||||||
|
|
||||||
$uploadDirectory = $this->config()->get('featured_images_directory');
|
$uploadDirectory = $this->config()->get('featured_images_directory');
|
||||||
if ($uploadDirectory != '') {
|
if ($uploadDirectory != '') {
|
||||||
$uploadField->setFolderName($uploadDirectory);
|
$uploadField?->setFolderName($uploadDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
$summaryField = $fields->dataFieldByName('Summary');
|
||||||
* @var FieldList $fields
|
$fields->removeByName('Summary');
|
||||||
*/
|
$summaryField?->setTitle('');
|
||||||
$fields->insertAfter('Content', $uploadField);
|
$summaryField?->setRows(5);
|
||||||
|
$summaryField?->setDescription(_t(
|
||||||
$summary = HtmlEditorField::create('Summary', false);
|
|
||||||
$summary->setRows(5);
|
|
||||||
$summary->setDescription(_t(
|
|
||||||
__CLASS__ . '.SUMMARY_DESCRIPTION',
|
__CLASS__ . '.SUMMARY_DESCRIPTION',
|
||||||
'If no summary is specified the first 30 words will be used.'
|
'If no summary is specified the first 30 words will be used.'
|
||||||
));
|
));
|
||||||
|
|
||||||
$summaryHolder = ToggleCompositeField::create(
|
if ($summaryField) {
|
||||||
'CustomSummary',
|
$summaryHolder = ToggleCompositeField::create(
|
||||||
_t(__CLASS__ . '.CUSTOMSUMMARY', 'Add A Custom Summary'),
|
'CustomSummary',
|
||||||
[
|
_t(__CLASS__ . '.CUSTOMSUMMARY', 'Add A Custom Summary'),
|
||||||
$summary,
|
[
|
||||||
]
|
$summaryField,
|
||||||
);
|
]
|
||||||
$summaryHolder->setHeadingLevel(4);
|
);
|
||||||
$summaryHolder->addExtraClass('custom-summary');
|
$summaryHolder->setHeadingLevel(4);
|
||||||
|
$summaryHolder->addExtraClass('custom-summary');
|
||||||
|
|
||||||
if ($this->Summary) {
|
if ($this->Summary) {
|
||||||
$summaryHolder->setStartClosed(false);
|
$summaryHolder->setStartClosed(false);
|
||||||
|
}
|
||||||
|
$fields->insertAfter($uploadField ? 'FeaturedImage' : 'Content', $summaryHolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
$fields->insertAfter('FeaturedImage', $summaryHolder);
|
|
||||||
|
|
||||||
$authorField = ListboxField::create(
|
$authorField = ListboxField::create(
|
||||||
'Authors',
|
'Authors',
|
||||||
_t(__CLASS__ . '.Authors', 'Authors'),
|
_t(__CLASS__ . '.Authors', 'Authors'),
|
||||||
@ -312,10 +314,9 @@ class BlogPost extends Page
|
|||||||
$authorNames = $authorNames->performDisabledTransformation();
|
$authorNames = $authorNames->performDisabledTransformation();
|
||||||
}
|
}
|
||||||
|
|
||||||
$publishDate = DatetimeField::create('PublishDate', _t(__CLASS__ . '.PublishDate', 'Publish Date'));
|
$publishDate = $fields->dataFieldByName('PublishDate');
|
||||||
|
|
||||||
if (!$this->PublishDate) {
|
if (!$this->PublishDate) {
|
||||||
$publishDate->setDescription(
|
$publishDate?->setDescription(
|
||||||
_t(
|
_t(
|
||||||
__CLASS__ . '.PublishDate_Description',
|
__CLASS__ . '.PublishDate_Description',
|
||||||
'Will be set to "now" if published without a value.'
|
'Will be set to "now" if published without a value.'
|
||||||
@ -323,35 +324,23 @@ class BlogPost extends Page
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get categories and tags
|
$postOptions = [];
|
||||||
$parent = $this->Parent();
|
if ($publishDate) {
|
||||||
$categories = $parent instanceof Blog
|
$postOptions[] = $publishDate;
|
||||||
? $parent->Categories()
|
}
|
||||||
: BlogCategory::get();
|
$categories = $fields->dataFieldByName('Categories');
|
||||||
$tags = $parent instanceof Blog
|
if ($categories) {
|
||||||
? $parent->Tags()
|
$postOptions[] = $categories;
|
||||||
: BlogTag::get();
|
}
|
||||||
|
$tags = $fields->dataFieldByName('Tags');
|
||||||
|
if ($tags) {
|
||||||
|
$postOptions[] = $tags;
|
||||||
|
}
|
||||||
|
|
||||||
$fields->addFieldsToTab(
|
$fields->addFieldsToTab(
|
||||||
'Root.PostOptions',
|
'Root.PostOptions',
|
||||||
[
|
[
|
||||||
$publishDate,
|
...$postOptions,
|
||||||
TagField::create(
|
|
||||||
'Categories',
|
|
||||||
_t(__CLASS__ . '.Categories', 'Categories'),
|
|
||||||
$categories,
|
|
||||||
$this->Categories()
|
|
||||||
)
|
|
||||||
->setCanCreate($this->canCreateCategories())
|
|
||||||
->setShouldLazyLoad(true),
|
|
||||||
TagField::create(
|
|
||||||
'Tags',
|
|
||||||
_t(__CLASS__ . '.Tags', 'Tags'),
|
|
||||||
$tags,
|
|
||||||
$this->Tags()
|
|
||||||
)
|
|
||||||
->setCanCreate($this->canCreateTags())
|
|
||||||
->setShouldLazyLoad(true),
|
|
||||||
$authorField,
|
$authorField,
|
||||||
$authorNames
|
$authorNames
|
||||||
]
|
]
|
||||||
@ -363,8 +352,6 @@ class BlogPost extends Page
|
|||||||
|
|
||||||
$fields = parent::getCMSFields();
|
$fields = parent::getCMSFields();
|
||||||
|
|
||||||
$fields->fieldByName('Root')->setTemplate('TabSet_holder');
|
|
||||||
|
|
||||||
return $fields;
|
return $fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
<div class="blog-admin-outer">
|
|
||||||
<%-- this resets ths template (from TabSet_holder) and renders using forTemplate --%>
|
|
||||||
$setTemplate('')
|
|
||||||
</div>
|
|
Loading…
Reference in New Issue
Block a user