From 58c080db5a6a0b313cf16600f5450d1817efd799 Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Mon, 30 Sep 2019 10:50:55 +1300 Subject: [PATCH] FEATURE Option placeholder for upload folder id (#9262) * FEATURE Option placeholder for upload folder id * ENHANCEMENT Add setFolderName() to TinyMCEConfig * Typehint return type * Add type to param --- src/Forms/HTMLEditor/TinyMCEConfig.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Forms/HTMLEditor/TinyMCEConfig.php b/src/Forms/HTMLEditor/TinyMCEConfig.php index 06314e750..3b0b6d9dc 100644 --- a/src/Forms/HTMLEditor/TinyMCEConfig.php +++ b/src/Forms/HTMLEditor/TinyMCEConfig.php @@ -3,9 +3,9 @@ namespace SilverStripe\Forms\HTMLEditor; use Exception; +use SilverStripe\Assets\Folder; use SilverStripe\Control\Controller; use SilverStripe\Control\Director; -use SilverStripe\Core\Convert; use SilverStripe\Core\Injector\Injector; use SilverStripe\Core\Manifest\Module; use SilverStripe\Core\Manifest\ModuleLoader; @@ -268,6 +268,7 @@ class TinyMCEConfig extends HTMLEditorConfig 'menubar' => false, 'language' => 'en', 'branding' => false, + 'upload_folder_id' => null, // Set folder ID for insert media dialog ]; /** @@ -844,4 +845,19 @@ class TinyMCEConfig extends HTMLEditorConfig Deprecation::notice('5.0', 'Set base_dir or editor_css config instead'); return ModuleLoader::getModule('silverstripe/admin'); } + + + /** + * Sets the upload folder name used by the insert media dialog + * + * @param string $folderName + * @return $this + */ + public function setFolderName(string $folderName): self + { + $folder = Folder::find_or_make($folderName); + $folderID = $folder ? $folder->ID : null; + $this->setOption('upload_folder_id', $folderID); + return $this; + } }