diff --git a/.upgrade.yml b/.upgrade.yml
index c793add3c..74caf9ebc 100644
--- a/.upgrade.yml
+++ b/.upgrade.yml
@@ -352,7 +352,7 @@ mappings:
HTMLEditorConfig: SilverStripe\Forms\HTMLEditor\HTMLEditorConfig
HTMLEditorField: SilverStripe\Forms\HTMLEditor\HTMLEditorField
HTMLEditorField_Readonly: SilverStripe\Forms\HTMLEditor\HTMLEditorField_Readonly
- HTMLEditorField_Toolbar: SilverStripe\Forms\HTMLEditor\HTMLEditorField_Toolbar
+ HTMLEditorField_Toolbar: SilverStripe\Admin\ModalController\HTMLEditorField_Toolbar
HTMLEditorField_Embed: SilverStripe\Forms\HTMLEditor\HTMLEditorField_Embed
HTMLEditorField_File: SilverStripe\Forms\HTMLEditor\HTMLEditorField_File
HTMLEditorField_Flash: SilverStripe\Forms\HTMLEditor\HTMLEditorField_Flash
diff --git a/docs/en/02_Developer_Guides/03_Forms/Field_types/03_HTMLEditorField.md b/docs/en/02_Developer_Guides/03_Forms/Field_types/03_HTMLEditorField.md
index fa8bc7471..ace321085 100644
--- a/docs/en/02_Developer_Guides/03_Forms/Field_types/03_HTMLEditorField.md
+++ b/docs/en/02_Developer_Guides/03_Forms/Field_types/03_HTMLEditorField.md
@@ -261,19 +261,11 @@ of the CMS you have to take care of instantiate yourself:
:::php
// File: mysite/code/MyController.php
class MyObjectController extends Controller {
- public function EditorToolbar() {
- return HtmlEditorField_Toolbar::create($this, "EditorToolbar");
+ public function Modals() {
+ return ModalController::create($this, "Modals");
}
}
- :::ss
- // File: mysite/templates/MyController.ss
- $Form
- <% with $EditorToolbar %>
- $MediaForm
- $LinkForm
- <% end_with %>
-
Note: The dialogs rely on CMS-access, e.g. for uploading and browsing files,
so this is considered advanced usage of the field.
diff --git a/docs/en/04_Changelogs/4.0.0.md b/docs/en/04_Changelogs/4.0.0.md
index 4ba1342f5..8d07b6fb3 100644
--- a/docs/en/04_Changelogs/4.0.0.md
+++ b/docs/en/04_Changelogs/4.0.0.md
@@ -1309,6 +1309,8 @@ After (`mysite/_config/config.yml`):
* `getsubtree()` -> moved to `CMSMain`
* `updatetreenodes()` -> moved to `CMSMain`
* `savetreenodes()` -> moved to `CMSMain`
+ * `EditorToolbar()` method renamed to `Modals()` and now returns a `ModalController` handler
+ instance rather than a `HTMLEditorField_Toolbar`
* Some `Director` API have been removed.
* $dev_servers
* $test_servers
@@ -1857,6 +1859,12 @@ New `TimeField` methods replace `getConfig()` / `setConfig()`
* `setOption`
* Removed `MemberDatetimeOptionsetField` (no replacement)
* Removed `DateField_View_JQuery` (replaced with native HTML5 support in `DateField`)
+* The following HTMLEditorField_* classes have been removed:
+ * `HTMLEditorField_Toolbar` (replaced With `ModalController` in admin module)
+ * `HTMLEditorField_Embed` (replaced with `EmbedResource` in asset-admin module)
+ * `HTMLEditorField_File`
+ * `HTMLEditorField_Flash`
+ * `HTMLEditorField_Image`
### i18n API
diff --git a/src/Forms/HTMLEditor/HTMLEditorField_Embed.php b/src/Forms/HTMLEditor/HTMLEditorField_Embed.php
deleted file mode 100644
index 40489c8fe..000000000
--- a/src/Forms/HTMLEditor/HTMLEditorField_Embed.php
+++ /dev/null
@@ -1,167 +0,0 @@
- 'Varchar',
- 'Info' => 'Varchar'
- );
-
- /**
- * Embed result
- *
- * @var Adapter
- */
- protected $embed;
-
- public function __construct($url, File $file = null)
- {
- parent::__construct($url, $file);
- $this->embed = Embed::create($url);
- if (!$this->embed) {
- $controller = Controller::curr();
- $response = $controller->getResponse();
- $response->addHeader(
- 'X-Status',
- rawurlencode(_t(
- 'SilverStripe\\Forms\\HTMLEditor\\HTMLEditorField.URLNOTANOEMBEDRESOURCE',
- "The URL '{url}' could not be turned into a media resource.",
- "The given URL is not a valid Oembed resource; the embed element couldn't be created.",
- array('url' => $url)
- ))
- );
- $response->setStatusCode(404);
-
- throw new HTTPResponse_Exception($response);
- }
- }
-
- /**
- * Get file-edit fields for this filed
- *
- * @return FieldList
- */
- public function getFields()
- {
- $fields = parent::getFields();
- if ($this->getType() === 'photo') {
- $fields->insertBefore('CaptionText', new TextField(
- 'AltText',
- _t('SilverStripe\\Forms\\HTMLEditor\\HTMLEditorField.IMAGEALTTEXT', 'Alternative text (alt) - shown if image can\'t be displayed'),
- $this->Title,
- 80
- ));
- $fields->insertBefore('CaptionText', new TextField(
- 'Title',
- _t('SilverStripe\\Forms\\HTMLEditor\\HTMLEditorField.IMAGETITLE', 'Title text (tooltip) - for additional information about the image')
- ));
- }
- return $fields;
- }
-
- /**
- * Get width of this Embed
- *
- * @return int
- */
- public function getWidth()
- {
- return $this->embed->getWidth() ?: 100;
- }
-
- /**
- * Get height of this Embed
- *
- * @return int
- */
- public function getHeight()
- {
- return $this->embed->getHeight() ?: 100;
- }
-
- public function getPreviewURL()
- {
- // Use thumbnail url
- if ($this->embed->image) {
- return $this->embed->image;
- }
-
- // Use direct image type
- if ($this->getType() == 'photo' && !empty($this->embed->url)) {
- return $this->embed->url;
- }
-
- // Default media
- return FRAMEWORK_ADMIN_DIR . '/client/dist/images/src/default_media.png';
- }
-
- public function getName()
- {
- if ($this->embed->title) {
- return $this->embed->title;
- } else {
- return parent::getName();
- }
- }
-
- /**
- * Get Embed type
- *
- * @return string
- */
- public function getType()
- {
- return $this->embed->type;
- }
-
- /**
- * Get filetype
- *
- * @return string
- */
- public function getFileType()
- {
- return $this->getType()
- ?: parent::getFileType();
- }
-
- /**
- * @return AdapterInterface
- */
- public function getEmbed()
- {
- return $this->embed;
- }
-
- public function appCategory()
- {
- return 'embed';
- }
-
- /**
- * Info for this Embed
- *
- * @return string
- */
- public function getInfo()
- {
- return $this->embed->info;
- }
-}
diff --git a/src/Forms/HTMLEditor/HTMLEditorField_File.php b/src/Forms/HTMLEditor/HTMLEditorField_File.php
deleted file mode 100644
index 3dd3bd215..000000000
--- a/src/Forms/HTMLEditor/HTMLEditorField_File.php
+++ /dev/null
@@ -1,402 +0,0 @@
- 'Varchar',
- 'Name' => 'Varchar'
- );
-
- /**
- * Absolute URL to asset
- *
- * @var string
- */
- protected $url;
-
- /**
- * File dataobject (if available)
- *
- * @var File
- */
- protected $file;
-
- /**
- * @param string $url
- * @param File $file
- */
- public function __construct($url, File $file = null)
- {
- $this->url = $url;
- $this->file = $file;
- $this->failover = $file;
- parent::__construct();
- }
-
- /**
- * @return FieldList
- */
- public function getFields()
- {
- $fields = new FieldList(
- CompositeField::create(
- CompositeField::create(LiteralField::create("ImageFull", $this->getPreview()))
- ->setName("FilePreviewImage")
- ->addExtraClass('cms-file-info-preview'),
- CompositeField::create($this->getDetailFields())
- ->setName("FilePreviewData")
- ->addExtraClass('cms-file-info-data')
- )
- ->setName("FilePreview")
- ->addExtraClass('cms-file-info'),
- TextField::create('CaptionText', _t('SilverStripe\\Forms\\HTMLEditor\\HTMLEditorField.CAPTIONTEXT', 'Caption text')),
- DropdownField::create(
- 'CSSClass',
- _t('SilverStripe\\Forms\\HTMLEditor\\HTMLEditorField.CSSCLASS', 'Alignment / style'),
- array(
- 'leftAlone' => _t('SilverStripe\\Forms\\HTMLEditor\\HTMLEditorField.CSSCLASSLEFTALONE', 'On the left, on its own.'),
- 'center' => _t('SilverStripe\\Forms\\HTMLEditor\\HTMLEditorField.CSSCLASSCENTER', 'Centered, on its own.'),
- 'left' => _t('SilverStripe\\Forms\\HTMLEditor\\HTMLEditorField.CSSCLASSLEFT', 'On the left, with text wrapping around.'),
- 'right' => _t('SilverStripe\\Forms\\HTMLEditor\\HTMLEditorField.CSSCLASSRIGHT', 'On the right, with text wrapping around.')
- ),
- HtmlEditorField::config()->uninherited('media_alignment')
- ),
- FieldGroup::create(
- _t('SilverStripe\\Forms\\HTMLEditor\\HTMLEditorField.IMAGEDIMENSIONS', 'Dimensions'),
- TextField::create(
- 'Width',
- _t('SilverStripe\\Forms\\HTMLEditor\\HTMLEditorField.IMAGEWIDTHPX', 'Width'),
- $this->getInsertWidth()
- )->setMaxLength(5),
- TextField::create(
- 'Height',
- " x " . _t('SilverStripe\\Forms\\HTMLEditor\\HTMLEditorField.IMAGEHEIGHTPX', 'Height'),
- $this->getInsertHeight()
- )->setMaxLength(5)
- )->addExtraClass('dimensions last'),
- HiddenField::create('URL', false, $this->getURL()),
- HiddenField::create('FileID', false, $this->getFileID())
- );
- return $fields;
- }
-
- /**
- * Get list of fields for previewing this records details
- *
- * @return FieldList
- */
- protected function getDetailFields()
- {
- $fields = new FieldList(
- ReadonlyField::create("FileType", _t(__CLASS__.'.TYPE', 'File type'), $this->getFileType()),
- HTMLReadonlyField::create(
- 'ClickableURL',
- _t(__CLASS__.'.URL', 'URL'),
- $this->getExternalLink()
- )
- );
- // Get file size
- if ($this->getSize()) {
- $fields->insertAfter(
- 'FileType',
- ReadonlyField::create("Size", _t(__CLASS__.'.SIZE', 'File size'), $this->getSize())
- );
- }
- // Get modified details of local record
- if ($this->getFile()) {
- $fields->push(new DateField_Disabled(
- "Created",
- _t(__CLASS__.'.CREATED', 'First uploaded'),
- $this->getFile()->Created
- ));
- $fields->push(new DateField_Disabled(
- "LastEdited",
- _t(__CLASS__.'.LASTEDIT', 'Last changed'),
- $this->getFile()->LastEdited
- ));
- }
- return $fields;
- }
-
- /**
- * Get file DataObject
- *
- * Might not be set (for remote files)
- *
- * @return File
- */
- public function getFile()
- {
- return $this->file;
- }
-
- /**
- * Get file ID
- *
- * @return int
- */
- public function getFileID()
- {
- if ($file = $this->getFile()) {
- return $file->ID;
- }
- return null;
- }
-
- /**
- * Get absolute URL
- *
- * @return string
- */
- public function getURL()
- {
- return $this->url;
- }
-
- /**
- * Get basename
- *
- * @return string
- */
- public function getName()
- {
- return $this->file
- ? $this->file->Name
- : preg_replace('/\?.*/', '', basename($this->url));
- }
-
- /**
- * Get descriptive file type
- *
- * @return string
- */
- public function getFileType()
- {
- return File::get_file_type($this->getName());
- }
-
- /**
- * Get file size (if known) as string
- *
- * @return string|false String value, or false if doesn't exist
- */
- public function getSize()
- {
- if ($this->file) {
- return $this->file->getSize();
- }
- return false;
- }
-
- /**
- * HTML content for preview
- *
- * @return string HTML
- */
- public function getPreview()
- {
- $preview = $this->extend('getPreview');
- if ($preview) {
- return $preview;
- }
-
- // Generate tag from preview
- $thumbnailURL = Convert::raw2att(
- Controller::join_links($this->getPreviewURL(), "?r=" . rand(1, 100000))
- );
- $fileName = Convert::raw2att($this->Name);
- return sprintf(
- "\n",
- $thumbnailURL,
- $fileName
- );
- }
-
- /**
- * HTML Content for external link
- *
- * @return string
- */
- public function getExternalLink()
- {
- $title = $this->file
- ? $this->file->getTitle()
- : $this->getName();
- return sprintf(
- '%1$s',
- Convert::raw2att($this->url),
- Convert::raw2att($title)
- );
- }
-
- /**
- * Generate thumbnail url
- *
- * @return string
- */
- public function getPreviewURL()
- {
- // Get preview from file
- if ($this->file) {
- return $this->getFilePreviewURL();
- }
-
- // Generate default icon html
- return File::get_icon_for_extension($this->getExtension());
- }
-
- /**
- * Generate thumbnail URL from file dataobject (if available)
- *
- * @return string
- */
- protected function getFilePreviewURL()
- {
- // Get preview from file
- if ($this->file) {
- $width = HTMLEditorField_File::config()->media_preview_width;
- $height = HTMLEditorField_File::config()->media_preview_height;
- return $this->file->ThumbnailURL($width, $height);
- }
- return null;
- }
-
- /**
- * Get file extension
- *
- * @return string
- */
- public function getExtension()
- {
- $extension = File::get_file_extension($this->getName());
- return strtolower($extension);
- }
-
- /**
- * Category name
- *
- * @return string
- */
- public function appCategory()
- {
- if ($this->file) {
- return $this->file->appCategory();
- } else {
- return File::get_app_category($this->getExtension());
- }
- }
-
- /**
- * Get height of this item
- */
- public function getHeight()
- {
- if ($this->file) {
- $height = $this->file->getHeight();
- if ($height) {
- return $height;
- }
- }
- return HTMLEditorField_File::config()->insert_height;
- }
-
- /**
- * Get width of this item
- *
- * @return int
- */
- public function getWidth()
- {
- if ($this->file) {
- $width = $this->file->getWidth();
- if ($width) {
- return $width;
- }
- }
- return HTMLEditorField_File::config()->insert_width;
- }
-
- /**
- * Provide an initial width for inserted media, restricted based on $embed_width
- *
- * @return int
- */
- public function getInsertWidth()
- {
- $width = $this->getWidth();
- $maxWidth = HTMLEditorField_File::config()->insert_width;
- return ($width <= $maxWidth) ? $width : $maxWidth;
- }
-
- /**
- * Provide an initial height for inserted media, scaled proportionally to the initial width
- *
- * @return int
- */
- public function getInsertHeight()
- {
- $width = $this->getWidth();
- $height = $this->getHeight();
- $maxWidth = HTMLEditorField_File::config()->insert_width;
- return ($width <= $maxWidth) ? $height : round($height * ($maxWidth / $width));
- }
-}
diff --git a/src/Forms/HTMLEditor/HTMLEditorField_Flash.php b/src/Forms/HTMLEditor/HTMLEditorField_Flash.php
deleted file mode 100644
index c39b64970..000000000
--- a/src/Forms/HTMLEditor/HTMLEditorField_Flash.php
+++ /dev/null
@@ -1,17 +0,0 @@
-removeByName('CaptionText', true);
- return $fields;
- }
-}
diff --git a/src/Forms/HTMLEditor/HTMLEditorField_Image.php b/src/Forms/HTMLEditor/HTMLEditorField_Image.php
deleted file mode 100644
index d53cd315b..000000000
--- a/src/Forms/HTMLEditor/HTMLEditorField_Image.php
+++ /dev/null
@@ -1,213 +0,0 @@
-size = $size;
- }
-
- // Get dimensions of remote file
- $info = @getimagesize($url);
- if ($info) {
- $this->width = $info[0];
- $this->height = $info[1];
- }
- }
-
- public function getFields()
- {
- $fields = parent::getFields();
-
- // Alt text
- $fields->insertBefore(
- 'CaptionText',
- TextField::create(
- 'AltText',
- _t('SilverStripe\\Forms\\HTMLEditor\\HTMLEditorField.IMAGEALT', 'Alternative text (alt)'),
- $this->Title,
- 80
- )->setDescription(
- _t('SilverStripe\\Forms\\HTMLEditor\\HTMLEditorField.IMAGEALTTEXTDESC', 'Shown to screen readers or if image can\'t be displayed')
- )
- );
-
- // Tooltip
- $fields->insertAfter(
- 'AltText',
- TextField::create(
- 'Title',
- _t('SilverStripe\\Forms\\HTMLEditor\\HTMLEditorField.IMAGETITLETEXT', 'Title text (tooltip)')
- )->setDescription(
- _t('SilverStripe\\Forms\\HTMLEditor\\HTMLEditorField.IMAGETITLETEXTDESC', 'For additional information about the image')
- )
- );
-
- return $fields;
- }
-
- protected function getDetailFields()
- {
- $fields = parent::getDetailFields();
- $width = $this->getOriginalWidth();
- $height = $this->getOriginalHeight();
-
- // Show dimensions of original
- if ($width && $height) {
- $fields->insertAfter(
- 'ClickableURL',
- ReadonlyField::create(
- "OriginalWidth",
- _t(__CLASS__.'.WIDTH', 'Width'),
- $width
- )
- );
- $fields->insertAfter(
- 'OriginalWidth',
- ReadonlyField::create(
- "OriginalHeight",
- _t(__CLASS__.'.HEIGHT', 'Height'),
- $height
- )
- );
- }
- return $fields;
- }
-
- /**
- * Get width of original, if known
- *
- * @return int
- */
- public function getOriginalWidth()
- {
- if ($this->width) {
- return $this->width;
- }
- if ($this->file) {
- $width = $this->file->getWidth();
- if ($width) {
- return $width;
- }
- }
- return null;
- }
-
- /**
- * Get height of original, if known
- *
- * @return int
- */
- public function getOriginalHeight()
- {
- if ($this->height) {
- return $this->height;
- }
-
- if ($this->file) {
- $height = $this->file->getHeight();
- if ($height) {
- return $height;
- }
- }
- return null;
- }
-
- public function getWidth()
- {
- if ($this->width) {
- return $this->width;
- }
- return parent::getWidth();
- }
-
- public function getHeight()
- {
- if ($this->height) {
- return $this->height;
- }
- return parent::getHeight();
- }
-
- public function getSize()
- {
- if ($this->size) {
- return File::format_size($this->size);
- }
- return parent::getSize();
- }
-
- /**
- * Provide an initial width for inserted image, restricted based on $embed_width
- *
- * @return int
- */
- public function getInsertWidth()
- {
- $width = $this->getWidth();
- $maxWidth = HTMLEditorField_Image::config()->insert_width;
- return $width <= $maxWidth
- ? $width
- : $maxWidth;
- }
-
- /**
- * Provide an initial height for inserted image, scaled proportionally to the initial width
- *
- * @return int
- */
- public function getInsertHeight()
- {
- $width = $this->getWidth();
- $height = $this->getHeight();
- $maxWidth = HTMLEditorField_Image::config()->insert_width;
- return ($width <= $maxWidth) ? $height : round($height * ($maxWidth / $width));
- }
-
- public function getPreviewURL()
- {
- // Get preview from file
- if ($this->file) {
- return $this->getFilePreviewURL();
- }
-
- // Embed image directly
- return $this->url;
- }
-}
diff --git a/src/Forms/HTMLEditor/HTMLEditorField_Toolbar.php b/src/Forms/HTMLEditor/HTMLEditorField_Toolbar.php
deleted file mode 100644
index d9f5a5dcf..000000000
--- a/src/Forms/HTMLEditor/HTMLEditorField_Toolbar.php
+++ /dev/null
@@ -1,495 +0,0 @@
-EditorToolbar()}.
- */
-class HTMLEditorField_Toolbar extends RequestHandler
-{
-
- private static $allowed_actions = array(
- 'LinkForm',
- 'EditorExternalLink',
- 'EditorEmailLink',
- 'viewfile',
- 'getanchors'
- );
-
- /**
- * @return string
- */
- public function getTemplateViewFile()
- {
- return SSViewer::get_templates_by_class(static::class, '_viewfile', __CLASS__);
- }
-
- /**
- * @var Controller
- */
- protected $controller;
-
- /**
- * @var string
- */
- protected $name;
-
- public function __construct($controller, $name)
- {
- parent::__construct();
-
- $this->controller = $controller;
- $this->name = $name;
- }
-
- public function forTemplate()
- {
- return sprintf(
- '