Skip to content

Instantly share code, notes, and snippets.

@EclipseGc
Created September 15, 2014 17:29
Show Gist options
  • Save EclipseGc/b225e7e7a920c02ea005 to your computer and use it in GitHub Desktop.
Save EclipseGc/b225e7e7a920c02ea005 to your computer and use it in GitHub Desktop.
<?php
/**
* @file
* Contains FilterOEmbed.php.
*/
namespace Drupal\oembed\Plugin\Filter;
use Drupal\filter\FilterProcessResult;
use Drupal\filter\Plugin\FilterBase;
use Essence\Essence;
use Essence\Media;
/**
* Provides a filter to convert urls to oembed output.
*
* @Filter(
* id = "filter_oembed",
* title = @Translation("Convert urls to oembed output."),
* type = Drupal\filter\Plugin\FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE
* )
*/
class FilterOEmbed extends FilterBase {
/**
* {@inheritdoc}
*/
public function process($text, $langcode) {
$essence = Essence::instance();
// Hard coded a maxwidth/height to make it easier to test against for the moment. Not required.
$text = $essence->replace($text, array($this, 'embed'), [
'maxwidth' => 640,
'maxheight' => 480
]);
return new FilterProcessResult($text);
}
public function embed(Media $media) {
/**
* Do something with this object before returning the html if you like.
*/
return $media->get('html');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment