mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
Adding authors to posts
This commit is contained in:
parent
a81ff7067d
commit
a40ae58623
@ -21,6 +21,7 @@ class BlogPost extends Page {
|
|||||||
private static $many_many = array(
|
private static $many_many = array(
|
||||||
"Categories" => "BlogCategory",
|
"Categories" => "BlogCategory",
|
||||||
"Tags" => "BlogTag",
|
"Tags" => "BlogTag",
|
||||||
|
"Authors" => "Member",
|
||||||
);
|
);
|
||||||
|
|
||||||
private static $defaults = array(
|
private static $defaults = array(
|
||||||
@ -100,7 +101,27 @@ class BlogPost extends Page {
|
|||||||
"Tags",
|
"Tags",
|
||||||
_t("BlogPost.Tags", "Tags"),
|
_t("BlogPost.Tags", "Tags"),
|
||||||
$self->Parent()->Tags()->map()->toArray()
|
$self->Parent()->Tags()->map()->toArray()
|
||||||
)->setMultiple(true)
|
)->setMultiple(true),
|
||||||
|
ListboxField::create(
|
||||||
|
"Authors",
|
||||||
|
_t("BlogPost.Authors", "Authors"),
|
||||||
|
Member::get()->map()->toArray()
|
||||||
|
)->setMultiple(true),
|
||||||
|
FieldGroup::create(
|
||||||
|
LabelField::create(null, 'Add New Author')->addExtraClass("new-author-label left"),
|
||||||
|
TextField::create(
|
||||||
|
'AuthorFirstName',
|
||||||
|
''
|
||||||
|
)
|
||||||
|
->setAttribute('placeholder', 'First name')
|
||||||
|
->addExtraClass("new-author-first-name"),
|
||||||
|
TextField::create(
|
||||||
|
'AuthorLastName',
|
||||||
|
''
|
||||||
|
)
|
||||||
|
->setAttribute('placeholder', 'Last name')
|
||||||
|
->addExtraClass("new-author-first-name")
|
||||||
|
)->addExtraClass("field")
|
||||||
)->setTitle('Post Options');
|
)->setTitle('Post Options');
|
||||||
$publishDate->getDateField()->setConfig("showcalendar", true);
|
$publishDate->getDateField()->setConfig("showcalendar", true);
|
||||||
|
|
||||||
@ -123,6 +144,18 @@ class BlogPost extends Page {
|
|||||||
**/
|
**/
|
||||||
protected function onBeforeWrite() {
|
protected function onBeforeWrite() {
|
||||||
parent::onBeforeWrite();
|
parent::onBeforeWrite();
|
||||||
|
|
||||||
|
if(isset($this->AuthorFirstName) or isset($this->AuthorLastName)) {
|
||||||
|
$author = new Member();
|
||||||
|
|
||||||
|
if(isset($this->AuthorFirstName)) $author->FirstName = $this->AuthorFirstName;
|
||||||
|
if(isset($this->AuthorLastName)) $author->LastName = $this->AuthorLastName;
|
||||||
|
|
||||||
|
$author->write();
|
||||||
|
|
||||||
|
$this->Authors()->add($author);
|
||||||
|
}
|
||||||
|
|
||||||
if(!$this->PublishDate) $this->setCastedField("PublishDate", time());
|
if(!$this->PublishDate) $this->setCastedField("PublishDate", time());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
12
css/cms.css
12
css/cms.css
@ -97,3 +97,15 @@
|
|||||||
.blog-admin-sidebar.cms-content-tools .cms-panel-content {
|
.blog-admin-sidebar.cms-content-tools .cms-panel-content {
|
||||||
width: auto;
|
width: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.new-author-label {
|
||||||
|
width: 249px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.new-author-first-name {
|
||||||
|
margin-right: 5px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.new-author-first-name, .new-author-last-name {
|
||||||
|
width: 115px !important;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user