From dd18648ed1f2941d3f3a61e3c22713ac7c91be4f Mon Sep 17 00:00:00 2001 From: Tim Burt Date: Wed, 3 Jul 2019 12:21:36 +0100 Subject: [PATCH 1/5] Make featured images directory configurable --- docs/en/configuring-featured-images.md | 13 +++++++++++++ docs/en/index.md | 1 + src/Model/BlogPost.php | 13 +++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 docs/en/configuring-featured-images.md 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 */ From ea2fcd0b6ecb4c65cdb7fb2e82d515b7c52aa7e1 Mon Sep 17 00:00:00 2001 From: Ryan Potter Date: Mon, 1 Jul 2019 09:37:12 +1200 Subject: [PATCH 2/5] Added a method to set the button name in a GridFieldAddByDBField component --- .idea/misc.xml | 6 + .idea/modules.xml | 8 + .idea/silverstripe-blog.iml | 11 ++ .idea/vcs.xml | 6 + .idea/workspace.xml | 157 ++++++++++++++++++ src/Forms/GridField/GridFieldAddByDBField.php | 30 +++- 6 files changed, 216 insertions(+), 2 deletions(-) create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/silverstripe-blog.iml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..28a804d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..91ce0e0 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/silverstripe-blog.iml b/.idea/silverstripe-blog.iml new file mode 100644 index 0000000..c179ff9 --- /dev/null +++ b/.idea/silverstripe-blog.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..ad793fd --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,157 @@ + + + + + + + + + $PROJECT_DIR$/composer.json + + + + + + + + + + + + + + + + + + + + _t( + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - 1561930166221 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file From 14283d88b8d633b78e6595be441a7d2f1948552e Mon Sep 17 00:00:00 2001 From: Ryan Potter Date: Mon, 1 Jul 2019 10:32:19 +1200 Subject: [PATCH 4/5] Set docblock for the setButtonName method, and don't invalidate localisation text. --- .gitignore | 1 - src/Forms/GridField/GridFieldAddByDBField.php | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index bbe398c..80e016d 100755 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ /vendor/* -/.idea .sass-cache/* /node_modules/ **/*.js.map diff --git a/src/Forms/GridField/GridFieldAddByDBField.php b/src/Forms/GridField/GridFieldAddByDBField.php index 7a4b06f..43a0c43 100644 --- a/src/Forms/GridField/GridFieldAddByDBField.php +++ b/src/Forms/GridField/GridFieldAddByDBField.php @@ -152,7 +152,7 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP /** * Set the button name * - * @param $name + * @param $name string * @return $this */ public function setButtonName($name) @@ -211,7 +211,7 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP if (!$this->buttonName) { // provide a default button name, can be changed by calling {@link setButtonName()} on this component $objectName = $obj->i18n_singular_name(); - $this->buttonName = _t(__CLASS__ . '.ButtonName', 'Add {name}', array('name' => $objectName)); + $this->buttonName = _t(__CLASS__ . '.ButtonName', '{name}', ['name' => $objectName]); } $addAction = GridField_FormAction::create( @@ -219,7 +219,7 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP 'add', _t( __CLASS__ . '.Add', - '{name}', + 'Add {name}', 'Add button text', ['name' => $this->buttonName] ), From c134ce44c1b9b10c52ebaeae9f74729362506141 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Wed, 13 Feb 2019 09:13:10 +0700 Subject: [PATCH 5/5] Switch assertions to test the end of the strings --- tests/BlogPostTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/BlogPostTest.php b/tests/BlogPostTest.php index 4216af2..4439194 100644 --- a/tests/BlogPostTest.php +++ b/tests/BlogPostTest.php @@ -160,7 +160,7 @@ class BlogPostTest extends SapphireTest $archiveLink = $blogPost->getMonthlyArchiveLink($type); $this->assertContains('archive/', $archiveLink); - $this->assertContains($expected, $archiveLink); + $this->assertStringEndsWith($expected, $archiveLink); } /** @@ -182,6 +182,6 @@ class BlogPostTest extends SapphireTest $archiveLink = $blogPost->getYearlyArchiveLink(); $this->assertContains('archive/', $archiveLink); - $this->assertContains('/2013', $archiveLink); + $this->assertStringEndsWith('/2013', $archiveLink); } }