function template_preprocess_gutenberg_block__drupalmedia__drupal_media_entity in Gutenberg 8.2
Prepares variables for Drupal media Gutenberg block templates.
See also
template_preprocess_gutenberg_block
File
- ./
gutenberg.theme.inc, line 50 - Theme related functions and hooks for the Gutenberg module.
Code
function template_preprocess_gutenberg_block__drupalmedia__drupal_media_entity(&$variables) {
if (!empty($variables['block_attributes']['mediaEntityIds'])) {
/** @var \Drupal\gutenberg\MediaEntityRendererInterface $media_entity_renderer */
$media_entity_renderer = \Drupal::service('gutenberg.media_entity.renderer');
$variables['block_content'] = $media_entity_renderer
->renderArray(reset($variables['block_attributes']['mediaEntityIds']), $variables['block_attributes']['viewMode'] ?? 'default');
}
}