Adding authors to posts

This commit is contained in:
Christopher Pitt 2015-03-11 08:01:51 +13:00
parent a81ff7067d
commit a40ae58623
2 changed files with 53 additions and 8 deletions

View File

@ -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());
} }

View File

@ -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;
}