function media_library_preprocess_media in Drupal 9
Same name and namespace in other branches
- 8 core/modules/media_library/media_library.module \media_library_preprocess_media()
Implements hook_preprocess_media().
File
- core/
modules/ media_library/ media_library.module, line 228 - Contains hook implementations for the media_library module.
Code
function media_library_preprocess_media(&$variables) {
if ($variables['view_mode'] === 'media_library') {
/** @var \Drupal\media\MediaInterface $media */
$media = $variables['media'];
$variables['#cache']['contexts'][] = 'user.permissions';
$rel = $media
->access('edit') ? 'edit-form' : 'canonical';
$variables['url'] = $media
->toUrl($rel, [
'language' => $media
->language(),
]);
$variables += [
'preview_attributes' => new Attribute(),
'metadata_attributes' => new Attribute(),
];
$variables['status'] = $media
->isPublished();
}
}