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:
rdigitalg 2020-07-03 04:04:54 +03:00 committed by Steve Boyd
parent e341e0aee7
commit 56f15b1c14

View File

@ -14,7 +14,9 @@ use SilverStripe\View\HTML;
use SilverStripe\View\Parsers\ShortcodeHandler; use SilverStripe\View\Parsers\ShortcodeHandler;
use Embed\Adapters\Adapter; use Embed\Adapters\Adapter;
use Embed\Embed; use Embed\Embed;
use Embed\Exceptions\InvalidUrlException;
use SilverStripe\View\Parsers\ShortcodeParser; use SilverStripe\View\Parsers\ShortcodeParser;
use SilverStripe\Control\Director;
/** /**
* Provider for the [embed] shortcode tag used by the embedding service * Provider for the [embed] shortcode tag used by the embedding service
@ -89,7 +91,24 @@ class EmbedShortcodeProvider implements ShortcodeHandler
} }
// Process embed // 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 // Convert embed object into HTML
if ($embed && $embed instanceof Adapter) { if ($embed && $embed instanceof Adapter) {