diff --git a/localgov_core.links.task.yml b/localgov_core.links.task.yml deleted file mode 100644 index e3c55d1..0000000 --- a/localgov_core.links.task.yml +++ /dev/null @@ -1,5 +0,0 @@ -localgov_core.files: - title: 'Files' - parent_id: entity.media.collection - route_name: view.files.page_1 - weight: 100 diff --git a/modules/localgov_media/config/optional/views.view.media.yml b/modules/localgov_media/config/optional/views.view.media.yml index cfadf7d..219a930 100644 --- a/modules/localgov_media/config/optional/views.view.media.yml +++ b/modules/localgov_media/config/optional/views.view.media.yml @@ -6,6 +6,7 @@ dependencies: module: - entity_usage - image + - localgov_core - media - user id: media diff --git a/modules/localgov_media/localgov_media.links.task.yml b/modules/localgov_media/localgov_media.links.task.yml new file mode 100644 index 0000000..6697c28 --- /dev/null +++ b/modules/localgov_media/localgov_media.links.task.yml @@ -0,0 +1,2 @@ +localgov_core.files: + deriver: 'Drupal\localgov_media\Plugin\Derivative\FilesLocalTasks' diff --git a/modules/localgov_media/localgov_media.module b/modules/localgov_media/localgov_media.module index 96822b6..2e43aa5 100644 --- a/modules/localgov_media/localgov_media.module +++ b/modules/localgov_media/localgov_media.module @@ -9,6 +9,16 @@ use Drupal\Core\Config\FileStorage; use Drupal\localgov_roles\RolesHelper; use Drupal\user\Entity\Role; +/** + * Implements hook_links_discovered_alter(). + */ +function localgov_media_menu_links_discovered_alter(&$links): void { + // We move our files under media. + // @see https://github.com/localgovdrupal/localgov_core/pull/221 + // @see \Drupal\localgov_media\Plugin\Derivative\FilesLocalTasks + unset($links['admin_toolbar_tools.extra_links:view.files']); +} + /** * Implements hook_modules_installed(). */ diff --git a/modules/localgov_media/src/Plugin/Derivative/FilesLocalTasks.php b/modules/localgov_media/src/Plugin/Derivative/FilesLocalTasks.php new file mode 100644 index 0000000..b5fee56 --- /dev/null +++ b/modules/localgov_media/src/Plugin/Derivative/FilesLocalTasks.php @@ -0,0 +1,63 @@ +routeProvider = $route_provider; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, $base_plugin_id) { + return new static( + $container->get('router.route_provider'), + ); + } + + /** + * {@inheritdoc} + */ + public function getDerivativeDefinitions($base_plugin_definition) { + + try { + if ($this->routeProvider->getRouteByName('view.files.page_1')) { + $this->derivatives['view.files'] = $base_plugin_definition; + $this->derivatives['view.files']['parent_id'] = 'entity.media.collection'; + $this->derivatives['view.files']['title'] = 'Files'; + $this->derivatives['view.files']['route_name'] = 'view.files.page_1'; + $this->derivatives['view.files']['weight'] = 100; + } + } + catch (\Exception $exception) { + // Nothing to log here. + // getRouteByName throw an exception If a matching route cannot be found. + // However, if the route do not exists, it is not an error in this case. + } + return parent::getDerivativeDefinitions($base_plugin_definition); + } + +}