function MediaLibraryThemeHooks::preprocessMedia

Implements hook_preprocess_media().

Attributes

#[Hook('preprocess_media')]

File

core/modules/media_library/src/Hook/MediaLibraryThemeHooks.php, line 16

Class

MediaLibraryThemeHooks
Hook implementations for media_library.

Namespace

Drupal\media_library\Hook

Code

public function preprocessMedia(&$variables) : void {
  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.