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:
Guy Marriott 2020-07-17 10:32:10 -07:00 committed by GitHub
commit 87200439be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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
$embed = $embed->getEmbed();
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) {