public static function Blazy::buildIframeAttributes in Blazy 8
Modifies variables for iframes.
2 calls to Blazy::buildIframeAttributes()
- Blazy::buildAttributes in src/
Blazy.php - Prepares variables for blazy.html.twig templates.
- BlazyUnitTest::testBuildIframeAttributes in tests/
src/ Unit/ BlazyUnitTest.php - Tests \Drupal\blazy\Blazy\buildIframeAttributes.
File
- src/
Blazy.php, line 232
Class
- Blazy
- Implements BlazyInterface.
Namespace
Drupal\blazyCode
public static function buildIframeAttributes(&$variables) {
// Prepares a media player, and allows a tiny video preview without iframe.
// image : If iframe switch disabled, fallback to iframe, remove image.
// player: If no colorbox/photobox, it is an image to iframe switcher.
// data- : Gets consistent with colorbox to share JS manipulation.
$settings =& $variables['settings'];
$variables['image'] = empty($settings['media_switch']) ? [] : $variables['image'];
$settings['player'] = empty($settings['lightbox']) && $settings['media_switch'] != 'content';
$iframe['data-src'] = $settings['embed_url'];
$iframe['src'] = empty($settings['iframe_lazy']) ? $settings['embed_url'] : 'about:blank';
// Only lazyload if media switcher is empty, but iframe lazy enabled.
if (!empty($settings['iframe_lazy']) && empty($settings['media_switch'])) {
$iframe['class'][] = 'b-lazy';
}
// Prevents broken iframe when aspect ratio is empty.
if (empty($settings['ratio']) && !empty($settings['width'])) {
$iframe['width'] = $settings['width'];
$iframe['height'] = $settings['height'];
}
// Pass iframe attributes to template.
$settings['autoplay_url'] = empty($settings['autoplay_url']) ? $settings['embed_url'] : $settings['autoplay_url'];
$variables['iframe_attributes'] = new Attribute($iframe);
// Iframe is removed on lazyloaded, puts data at non-removable storage.
$variables['attributes']['data-media'] = Json::encode([
'type' => $settings['type'],
'scheme' => $settings['scheme'],
]);
}