Skip to content

Commit

Permalink
FIX Try Catch for embeded media (silverstripe#9424)
Browse files Browse the repository at this point in the history
* 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: [email protected] <[email protected]>
Co-authored-by: Steve Boyd <[email protected]>
Co-authored-by: Loz Calver <[email protected]>
  • Loading branch information
rdigitalg authored and emteknetnz committed Jul 17, 2020
1 parent e341e0a commit 56f15b1
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/View/Shortcodes/EmbedShortcodeProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
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
Expand Down Expand Up @@ -89,7 +91,24 @@ public static function handle_shortcode($arguments, $content, $parser, $shortcod
}

// 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) {
Expand Down

0 comments on commit 56f15b1

Please sign in to comment.