public function MediaOembedPathSubscriber::modifyHtml in Tome 8
Reacts to a modify HTML event.
Parameters
\Drupal\tome_static\Event\ModifyHtmlEvent $event: The event.
File
- modules/
tome_static/ src/ EventSubscriber/ MediaOembedPathSubscriber.php, line 35
Class
- MediaOembedPathSubscriber
- Converts Media OEmbed query parameters to static paths.
Namespace
Drupal\tome_static\EventSubscriberCode
public function modifyHtml(ModifyHtmlEvent $event) {
$html = $event
->getHtml();
$document = new \DOMDocument();
@$document
->loadHTML($html);
$xpath = new \DOMXPath($document);
/** @var \DOMElement $node */
foreach ($xpath
->query('//iframe[contains(@src,"/media/oembed?url=")]') as $node) {
$original_src = $node
->getAttribute('src');
$new_src = $this
->modifyUrl($original_src);
$event
->addInvokePath($original_src);
$event
->addExcludePath($new_src);
$html = str_replace($original_src, $new_src, $html);
$html = str_replace(htmlentities($original_src), $new_src, $html);
}
$event
->setHtml($html);
}