function MediaLibraryHooks::localTasksAlter

Implements hook_local_tasks_alter().

Removes tasks for the Media library if the view display no longer exists.

Attributes

#[Hook('local_tasks_alter')]

File

core/modules/media_library/src/Hook/MediaLibraryHooks.php, line 258

Class

MediaLibraryHooks
Hook implementations for media_library.

Namespace

Drupal\media_library\Hook

Code

public function localTasksAlter(&$local_tasks) : void {
  /** @var \Symfony\Component\Routing\RouteCollection $route_collection */
  $route_collection = \Drupal::service('router')->getRouteCollection();
  foreach ([
    'media_library.grid',
    'media_library.table',
  ] as $key) {
    if (isset($local_tasks[$key]) && !$route_collection->get($local_tasks[$key]['route_name'])) {
      unset($local_tasks[$key]);
    }
  }
}

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