mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #9600 from creative-commoners/pulls/4.6/embedded-media
Try Catch for embeded media - Backport to 4.6
This commit is contained in:
commit
87200439be
@ -14,7 +14,9 @@ use SilverStripe\View\HTML;
|
||||
use SilverStripe\View\Parsers\ShortcodeHandler;
|
||||
use Embed\Adapters\Adapter;
|
||||
use Embed\Embed;
|
||||
use Embed\Exceptions\InvalidUrlException;
|
||||
use SilverStripe\View\Parsers\ShortcodeParser;
|
||||
use SilverStripe\Control\Director;
|
||||
|
||||
/**
|
||||
* Provider for the [embed] shortcode tag used by the embedding service
|
||||
@ -89,7 +91,24 @@ class EmbedShortcodeProvider implements ShortcodeHandler
|
||||
}
|
||||
|
||||
// Process embed
|
||||
try {
|
||||
$embed = $embed->getEmbed();
|
||||
} catch (InvalidUrlException $e) {
|
||||
$message = (Director::isDev())
|
||||
? $e->getMessage()
|
||||
: _t(__CLASS__ . '.INVALID_URL', 'There was a problem loading the media.');
|
||||
|
||||
$attr = [
|
||||
'class' => 'ss-media-exception embed'
|
||||
];
|
||||
|
||||
$result = HTML::createTag(
|
||||
'div',
|
||||
$attr,
|
||||
HTML::createTag('p', [], $message)
|
||||
);
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Convert embed object into HTML
|
||||
if ($embed && $embed instanceof Adapter) {
|
||||
|
Loading…
Reference in New Issue
Block a user