function template_preprocess_media
Same name in other branches
- 9 core/modules/media/media.module \template_preprocess_media()
- 10 core/modules/media/media.module \template_preprocess_media()
- 11.x core/modules/media/media.module \template_preprocess_media()
Prepares variables for media templates.
Default template: media.html.twig.
Parameters
array $variables: An associative array containing:
- elements: An array of elements to display in view mode.
- media: The media item.
- name: The label for the media item.
- view_mode: View mode; e.g., 'full', 'teaser', etc.
File
-
core/
modules/ media/ media.module, line 158
Code
function template_preprocess_media(array &$variables) {
$variables['media'] = $variables['elements']['#media'];
$variables['view_mode'] = $variables['elements']['#view_mode'];
$variables['name'] = $variables['media']->label();
// Helpful $content variable for templates.
foreach (Element::children($variables['elements']) as $key) {
$variables['content'][$key] = $variables['elements'][$key];
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.