Created
September 15, 2014 17:29
-
-
Save EclipseGc/b225e7e7a920c02ea005 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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