IframeOnlyFormatter.php in Iframe 8
File
src/Plugin/Field/FieldFormatter/IframeOnlyFormatter.php
View source
<?php
namespace Drupal\iframe\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Render\Markup;
class IframeOnlyFormatter extends IframeDefaultFormatter {
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
foreach ($items as $delta => $item) {
if (empty($item->url)) {
continue;
}
if (!(property_exists($item, 'title') && $item->title !== null)) {
$item->title = '';
}
$elements[$delta] = [
'#markup' => Markup::create(IframeDefaultFormatter::iframeIframe('', $item->url, $item)),
'#allowed_tags' => [
'iframe',
'a',
'h3',
'style',
],
];
if (isset($settings['tokensupport']) && $settings['tokensupport']) {
$elements[$delta]['cache'] = [
'max-age' => 0,
];
}
}
return $elements;
}
}