diff --git a/_config.php b/_config.php index 8aaf823c7..9feca8ebc 100644 --- a/_config.php +++ b/_config.php @@ -1,9 +1,7 @@ register('file_link', array(File::class, 'handle_shortcode')) - ->register('embed', array(EmbedShortcodeProvider::class, 'handle_shortcode')) - ->register('image', array(Image::class, 'handle_shortcode')); - -// Shortcode parser which only regenerates shortcodes -ShortcodeParser::get('regenerator') - ->register('image', array(Image::class, 'regenerate_shortcode')); + ->register('embed', [EmbedShortcodeProvider::class, 'handle_shortcode']); // If you don't want to see deprecation errors for the new APIs, change this to 3.2.0-dev. Deprecation::notification_version('3.2.0'); diff --git a/docs/en/04_Changelogs/4.0.0.md b/docs/en/04_Changelogs/4.0.0.md index 119ee95af..b3a3fdc20 100644 --- a/docs/en/04_Changelogs/4.0.0.md +++ b/docs/en/04_Changelogs/4.0.0.md @@ -752,6 +752,45 @@ There are a few differences in this new API: A generic `manipulate` method may be used, although the callback for this method both is given, and should return, an `AssetStore` instance and file tuple (Filename, Hash, and Variant) rather than an Image_Backend. +#### Upgrading code that uses File or Image shortcode handler + +The `handle_shortcode` methods have been removed from the core File and Image classes and moved to separate classes in their own respective namespace. Image and File do not implement the ShortcodeHandler interface anymore. + +The shortcode handler for `File` has been moved to `SilverStripe\Assets\ShortcodesFileShortcodeProvider` and the Image handler has been moved to `SilverStripe\Assets\Shortcodes\ImageShortcodeProvider` + +Before this change, to use the handle_shortcode method, you would do something like this: + +``` +content, $parser, $shortcode); + } +} +``` + +In the new situation, this would look like this: + +``` +content, $parser, $shortcode); + } +} +``` + #### Upgrading code that uses composite db fields. The `CompositeDBField` interface has been replaced with an abstract class, `DBComposite`. In many cases, custom code @@ -1660,6 +1699,7 @@ The below methods have been added or had their functionality updated to `DBDate` below for upgrade notes. * New filesystem abstraction including new `DBFile` database field to hold file references. * `ShortcodeHandler` interface to help generate standard handlers for HTML shortcodes in the editor. +* `handle_shortcode` methods are removed from `File` and `Image` and moved to their own classes in `SilverStripe\Assets\Shortcodes` and are named `FileShortcodeProvider` and `ImageShortcodeProvider` respectively. * `AssetNameGenerator` interface, including a `DefaultAssetNameGenerator` implementation, which is used to generate renaming suggestions based on an original given filename in order to resolve file duplication issues. * `GeneratedAssetHandler` API now used to store and manage generated files (such as those used for error page @@ -1701,6 +1741,7 @@ appropriate mime types. The following file manipulations classes and methods hav * `Image::regenerateFormattedImages` method * `Image::getGeneratedImages` method * `Image::deleteFormattedImages` method +* `Image::handle_shortcode` moved to `SilverStripe\Assets\Shortcodes\ImageShortcodeProvider::handle_shortcode` * `AssetAdmin::deleteunusedthumbnails` method * `AssetAdmin::getUnusedThumbnails` method diff --git a/src/Forms/HTMLEditor/HTMLEditorField.php b/src/Forms/HTMLEditor/HTMLEditorField.php index 846e7f074..0e2af5cf0 100644 --- a/src/Forms/HTMLEditor/HTMLEditorField.php +++ b/src/Forms/HTMLEditor/HTMLEditorField.php @@ -2,7 +2,7 @@ namespace SilverStripe\Forms\HTMLEditor; -use SilverStripe\Assets\Image; +use SilverStripe\Assets\Shortcodes\ImageShortcodeProvider; use SilverStripe\Forms\TextareaField; use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DataObjectInterface; @@ -145,7 +145,7 @@ class HTMLEditorField extends TextareaField public function setValue($value, $data = null) { // Regenerate links prior to preview, so that the editor can see them. - $value = Image::regenerate_html_links($value); + $value = ImageShortcodeProvider::regenerate_html_links($value); return parent::setValue($value); } diff --git a/src/Forms/HTMLEditor/EmbedShortcodeProvider.php b/src/View/Shortcodes/EmbedShortcodeProvider.php similarity index 99% rename from src/Forms/HTMLEditor/EmbedShortcodeProvider.php rename to src/View/Shortcodes/EmbedShortcodeProvider.php index b27cae492..c3966a8dd 100644 --- a/src/Forms/HTMLEditor/EmbedShortcodeProvider.php +++ b/src/View/Shortcodes/EmbedShortcodeProvider.php @@ -1,6 +1,6 @@