Skip to content

Instantly share code, notes, and snippets.

@muskie9
Created May 1, 2018 17:59
Show Gist options
  • Save muskie9/bd2693506dd838f3c9fa4423e6b4108d to your computer and use it in GitHub Desktop.
Save muskie9/bd2693506dd838f3c9fa4423e6b4108d to your computer and use it in GitHub Desktop.
<?php
namespace Your\Namespace\Here;
use SilverStripe\Core\Convert;
use SilverStripe\View\HTML;
use SilverStripe\View\Shortcodes\EmbedShortcodeProvider as SSEmbedShortcodeProvider;
class MyEmbedShortcodeProvider extends SSEmbedShortcodeProvider
{
/**
* @param Adapter $embed
* @param array $arguments Additional shortcode params
* @return string
*/
public static function embedForTemplate($embed, $arguments)
{
switch ($embed->getType()) {
case 'video':
case 'rich':
// Attempt to inherit width (but leave height auto)
if (empty($arguments['width']) && $embed->getWidth()) {
$arguments['width'] = $embed->getWidth();
}
return static::videoEmbed($arguments, $embed->getCode());
case 'link':
return static::linkEmbed($arguments, $embed->getUrl(), $embed->getTitle());
case 'photo':
return static::photoEmbed($arguments, $embed->getUrl());
default:
return null;
}
}
/**
* Build video embed tag
*
* @param array $arguments
* @param string $content Raw HTML content
* @return string
*/
protected static function videoEmbed($arguments, $content)
{
$arguments['class'] = 'embed-responsive embed-responsive-16by9';
return parent::videoEmbed($arguments, $content);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment