public function BlazyVideoTrait::getMediaItem in Blazy 7
Gets the Media item thumbnail, or re-associate the file entity to ME.
Parameters
array $data: An array of data containing settings, and potential video thumbnail item.
object $media: The Media file entity.
1 call to BlazyVideoTrait::getMediaItem()
- BlazyFileFormatter::buildElement in src/
Plugin/ Field/ FieldFormatter/ BlazyFileFormatter.php - Build individual item if so configured such as for file entity goodness.
File
- src/
Plugin/ Field/ FieldFormatter/ BlazyVideoTrait.php, line 49
Class
- BlazyVideoTrait
- A Trait common for Media integration with field details.
Namespace
Drupal\blazy\Plugin\Field\FieldFormatterCode
public function getMediaItem(array &$data, $media = NULL) {
if ($this->targetType != 'file') {
return;
}
$settings = $data['settings'];
$settings['media_url'] = entity_uri($this->targetType, $media)['path'];
$settings['media_id'] = $media->fid;
$settings['type'] = $media->type;
$settings['media_uri'] = $media->uri;
$settings['view_mode'] = empty($settings['view_mode']) ? 'default' : $settings['view_mode'];
list($settings['scheme']) = array_pad(array_map('trim', explode(":", $media->uri, 2)), 2, NULL);
// Ensures disabling Media sub-modules while being used doesn't screw up.
try {
$wrapper = file_stream_wrapper_get_instance_by_uri($media->uri);
// No need for checking MediaReadOnlyStreamWrapper.
if (!is_object($wrapper)) {
throw new \Exception('Unable to find matching wrapper!');
}
// Extract the processed media data from their theme variables.
$media_data = BlazyMedia::getMediaData($settings);
// Wait! We got no way to fetch embed url from the media API?
$settings['input_url'] = drupal_strip_dangerous_protocols($wrapper
->interpolateUrl());
$settings['embed_url'] = isset($media_data['url']) ? $media_data['url'] : '';
$settings['autoplay_url'] = $this
->getAutoplayUrl($settings['embed_url']);
$settings['video_id'] = isset($media_data['video_id']) ? $media_data['video_id'] : '';
$settings['uri'] = $wrapper
->getLocalThumbnailPath();
$settings['image_url'] = file_create_url($settings['uri']);
} catch (\Exception $e) {
// Ignore.
}
// Collect what's needed for clarity.
$data['settings'] = $settings;
}