diff --git a/docs/en/configuring-featured-images.md b/docs/en/configuring-featured-images.md new file mode 100644 index 0000000..115d92c --- /dev/null +++ b/docs/en/configuring-featured-images.md @@ -0,0 +1,13 @@ +## Configuring featured images + +By default, featured images for the blog are uploaded to the default SilverStripe location. +If you prefer, you can specify a directory into which featured images will be uploaded by adding the following to your project's config: + + + +```yaml +SilverStripe\Blog\Model\BlogPost: + featured_images_directory: 'blog-images' +``` + +replacing 'blog-images' with the name of the directory you wish to use. \ No newline at end of file diff --git a/docs/en/index.md b/docs/en/index.md index 14460ad..955e9f0 100644 --- a/docs/en/index.md +++ b/docs/en/index.md @@ -5,6 +5,7 @@ * [Configuring blog when on large websites](configuring-large-websites.md) * [Configuring widgets](configuring-widgets.md) * [Configuring pagination](configuring-pagination.md) + * [Configuring featured image uploads](configuring-featured-images.md) ## CMS user help * [User guide](userguide/index.md) diff --git a/src/Model/BlogPost.php b/src/Model/BlogPost.php index 10a3f94..321f6a6 100644 --- a/src/Model/BlogPost.php +++ b/src/Model/BlogPost.php @@ -170,6 +170,14 @@ class BlogPost extends Page */ private static $minutes_to_read_wpm = 200; + /** + * Sets the upload directory for featured images to help keep your files organised + * + * @config + * @var string + */ + private static $featured_images_directory = null; + /** * Determine the role of the given member. * @@ -236,6 +244,11 @@ class BlogPost extends Page $uploadField = UploadField::create('FeaturedImage', _t(__CLASS__ . '.FeaturedImage', 'Featured Image')); $uploadField->getValidator()->setAllowedExtensions(['jpg', 'jpeg', 'png', 'gif']); + $uploadDirectory = $this->config()->get('featured_images_directory'); + if ($uploadDirectory != '') { + $uploadField->setFolderName($uploadDirectory); + } + /** * @var FieldList $fields */