oEmbedThumbnail.php in oEmbed 8
File
src/Element/oEmbedThumbnail.php
View source
<?php
namespace Drupal\oembed\Element;
class oEmbedThumbnail extends oEmbed {
public function getInfo() {
$class = get_class($this);
return array(
'#theme' => 'image',
'#path' => NULL,
'#width' => NULL,
'#height' => NULL,
'#alt' => '',
'#title' => NULL,
'#attributes' => array(),
'#embed' => NULL,
'#parameters' => array(),
'#pre_render' => array(
array(
$class,
'preRenderFetch',
),
array(
$class,
'preRenderThumbnail',
),
),
);
}
public static function preRenderThumbnail($element) {
if (!empty($element['#printed'])) {
return $element;
}
$embed = $element['#embed'];
if (empty($embed
->getThumbnailUrl())) {
$element['#printed'] = TRUE;
return $element;
}
self::oembed_pre_render_image_helper($element);
return $element;
}
private static function oembed_pre_render_image_helper(&$element) {
$embed = $element['#embed'];
$element['#uri'] = $embed
->getThumbnailUrl();
$element['#alt'] = oembed_alt_attr($embed);
$element['#title'] = $embed
->getTitle();
$element['#height'] = !empty($embed
->getThumbnailHeight()) ? $embed
->getThumbnailHeight() : NULL;
$element['#width'] = !empty($embed
->getThumbnailWidth()) ? $embed
->getThumbnailWidth() : NULL;
foreach (array(
'width',
'height',
'alt',
'title',
) as $key) {
if (isset($element['#attributes'][$key])) {
$element['#' . $key] = $element['#attributes'][$key];
}
}
}
}