mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FIX Try Catch for embeded media (#9424)
* Try Catch for embeded media * added missing namespaces, translatable message INVALID_URL * generate tag only once * catch after closing bracket * space after comma * Update src/View/Shortcodes/EmbedShortcodeProvider.php * Linting Co-authored-by: ivan@digitalgarage.ro <ivan@digitalgarage.ro> Co-authored-by: Steve Boyd <emteknetnz@gmail.com> Co-authored-by: Loz Calver <kinglozzer@gmail.com>
This commit is contained in:
parent
e341e0aee7
commit
56f15b1c14
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user