mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Pulls/4.0/shortcode namespacing (#7085)
* New shortcode providers, update config, docs * Use new ImageShortcodeProvider * Move tests * New shortcodes namespace * Move file and image shortcode registrations from framework to assets
This commit is contained in:
parent
15b4cf70ed
commit
ad9d4e6820
12
_config.php
12
_config.php
@ -1,9 +1,7 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\Assets\File;
|
||||
use SilverStripe\Assets\Image;
|
||||
use SilverStripe\Dev\Deprecation;
|
||||
use SilverStripe\Forms\HtmlEditor\EmbedShortcodeProvider;
|
||||
use SilverStripe\View\Shortcodes\EmbedShortcodeProvider;
|
||||
use SilverStripe\View\Parsers\ShortcodeParser;
|
||||
|
||||
/**
|
||||
@ -15,13 +13,7 @@ use SilverStripe\View\Parsers\ShortcodeParser;
|
||||
*/
|
||||
|
||||
ShortcodeParser::get('default')
|
||||
->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');
|
||||
|
@ -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:
|
||||
|
||||
```
|
||||
<?php
|
||||
|
||||
class MyShortcodeUser extends Object {
|
||||
|
||||
|
||||
private $content;
|
||||
|
||||
public function Content($arguments, $parser, $shortcode) {
|
||||
return File::handle_shortcode($arguments, $this->content, $parser, $shortcode);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
In the new situation, this would look like this:
|
||||
|
||||
```
|
||||
<?php
|
||||
|
||||
use SilverStripe\Assets\Shortcodes\FileShortcodeProvider;
|
||||
|
||||
class MyShortcodeUser extends Object {
|
||||
|
||||
private $content;
|
||||
|
||||
public function Content($arguments, $parser, $shortcode) {
|
||||
return FileShortcodeProvider::handle_shortcode($arguments, $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
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Forms\HtmlEditor;
|
||||
namespace SilverStripe\View\Shortcodes;
|
||||
|
||||
use SilverStripe\Core\Convert;
|
||||
use SilverStripe\Core\Injector\Injector;
|
@ -1,10 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Forms\Tests;
|
||||
namespace SilverStripe\View\Tests\Shortcodes;
|
||||
|
||||
use SilverStripe\Forms\HtmlEditor\EmbedShortcodeProvider;
|
||||
use SilverStripe\View\Shortcodes\EmbedShortcodeProvider;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\framework\tests\php\Forms\EmbedShortcodeProviderTest\MockResolver;
|
||||
|
||||
/**
|
||||
* Class EmbedShortcodeProviderTest
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\framework\tests\php\Forms\EmbedShortcodeProviderTest;
|
||||
namespace SilverStripe\View\Tests\Shortcodes;
|
||||
|
||||
use Embed\Http\DispatcherInterface;
|
||||
use Embed\Http\ImageResponse;
|
Loading…
Reference in New Issue
Block a user