function media_library_preprocess_media

Same name and namespace in other branches
  1. 9 core/modules/media_library/media_library.module \media_library_preprocess_media()
  2. 8.9.x core/modules/media_library/media_library.module \media_library_preprocess_media()
  3. 11.x 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

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();
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.