AmpIframe.php in Accelerated Mobile Pages (AMP) 8.2
File
src/Element/AmpIframe.php
View source
<?php
namespace Drupal\amp\Element;
use Drupal\filter\Element\ProcessedText;
use Lullabot\AMP\AMP;
use Drupal\amp\Service\AMPService;
class AmpIframe extends ProcessedText {
public function getInfo() {
$class = get_class($this);
return array(
'#text' => '',
'#format' => NULL,
'#filter_types_to_skip' => array(),
'#langcode' => '',
'#pre_render' => array(
array(
$class,
'preRenderText',
),
array(
$class,
'preRenderAmpIframe',
),
),
'#theme' => 'amp_iframe',
'#cache' => [
'contexts' => [
'url.query_args:amp',
'url.query_args:warnfix',
],
'tags' => [
'config:amp.settings',
],
],
);
}
public static function preRenderAmpIframe($element) {
$amp_service = \Drupal::getContainer()
->get('amp.utilities');
$amp = $amp_service
->createAMPConverter();
$amp
->loadHtml($element['#markup']);
$element['#markup'] = $amp
->convertToAmpHtml();
$element['#iframe'] = [
'#markup' => $element['#markup'],
];
$element['#iframe']['#attached']['library'][] = 'amp/amp.iframe';
return $element;
}
}
Classes
Name |
Description |
AmpIframe |
Provides a render element for an iframe rendered as an amp-iframe. |