diff --git a/code/model/BlogPost.php b/code/model/BlogPost.php index 08bc81c..00ac27e 100644 --- a/code/model/BlogPost.php +++ b/code/model/BlogPost.php @@ -132,16 +132,18 @@ class BlogPost extends Page { $options = BlogAdminSidebar::create( $publishDate = DatetimeField::create("PublishDate", _t("BlogPost.PublishDate", "Publish Date")), $urlSegment, - ListboxField::create( - "Categories", - _t("BlogPost.Categories", "Categories"), - $self->Parent()->Categories()->map()->toArray() - )->setMultiple(true), - ListboxField::create( - "Tags", - _t("BlogPost.Tags", "Tags"), - $self->Parent()->Tags()->map()->toArray() - )->setMultiple(true), + TagField::create( + 'Categories', + _t('BlogPost.Categories', 'Categories'), + BlogCategory::get()->map(), + $self->Parent()->Categories()->map() + ), + TagField::create( + 'Tags', + _t('BlogPost.Tags', 'Tags'), + BlogTag::get()->map(), + $self->Parent()->Tags()->map() + ), $authorField, $authorNames )->setTitle('Post Options'); @@ -184,7 +186,25 @@ class BlogPost extends Page { } } + /** + * Sets blog relationship on all categories and tags assigned to this post. + * + * @throws ValidationException + */ + public function onAfterWrite() + { + parent::onAfterWrite(); + foreach ($this->Categories() as $category) { + $category->BlogID = $this->ParentID; + $category->write(); + } + + foreach ($this->Tags() as $tag) { + $tag->BlogID = $this->ParentID; + $tag->write(); + } + } /** * Checks the publish date to see if the blog post has actually been published. diff --git a/composer.json b/composer.json index a3d50e3..c2dd63c 100755 --- a/composer.json +++ b/composer.json @@ -1,12 +1,17 @@ { - "name": "silverstripe/blog", - "description": "A fresh take on blogging in Silverstripe set out to tackle the issue of a cluttered Site Tree.", - "keywords": ["silverstripe", "blog", "news"], - "type": "silverstripe-module", - "require": { - "silverstripe/cms": ">=3.1.0", - "silverstripe/lumberjack": "~1.1" - }, + "name": "silverstripe/blog", + "description": "A fresh take on blogging in Silverstripe set out to tackle the issue of a cluttered Site Tree.", + "keywords": [ + "silverstripe", + "blog", + "news" + ], + "type": "silverstripe-module", + "require": { + "silverstripe/cms": ">=3.1.0", + "silverstripe/lumberjack": "~1.1", + "silverstripe/tag-field": "~1.0" + }, "require-dev": { "phpunit/PHPUnit": "~3.7@stable" }, @@ -15,15 +20,15 @@ "dev-master": "2.0.x-dev" } }, - "license": "BSD-2-Clause", - "authors": [ - { - "name": "Michael Strong", - "email": "github@michaelstrong.co.uk" - } - ], - "suggest": { - "silverstripe/widgets": "Some widgets come with the blog which are compatible with the widgets module.", - "silverstripe/comments": "This module adds comments to your blog." - } + "license": "BSD-2-Clause", + "authors": [ + { + "name": "Michael Strong", + "email": "github@michaelstrong.co.uk" + } + ], + "suggest": { + "silverstripe/widgets": "Some widgets come with the blog which are compatible with the widgets module.", + "silverstripe/comments": "This module adds comments to your blog." + } }