From 58ee468128fe10eaaae022e2c755bb80d190531a Mon Sep 17 00:00:00 2001 From: Marco Pagliarulo Date: Tue, 8 Apr 2025 22:18:04 +0100 Subject: [PATCH 1/4] With the view "files" disabled, localgov_core cause an exception --- localgov_core.links.task.yml | 4 +- src/Plugin/Derivative/FilesLocalTasks.php | 60 +++++++++++++++++++++++ 2 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 src/Plugin/Derivative/FilesLocalTasks.php diff --git a/localgov_core.links.task.yml b/localgov_core.links.task.yml index e3c55d1..c936133 100644 --- a/localgov_core.links.task.yml +++ b/localgov_core.links.task.yml @@ -1,5 +1,3 @@ localgov_core.files: - title: 'Files' - parent_id: entity.media.collection - route_name: view.files.page_1 + deriver: 'Drupal\localgov_core\Plugin\Derivative\FilesLocalTasks' weight: 100 diff --git a/src/Plugin/Derivative/FilesLocalTasks.php b/src/Plugin/Derivative/FilesLocalTasks.php new file mode 100644 index 0000000..7bce38d --- /dev/null +++ b/src/Plugin/Derivative/FilesLocalTasks.php @@ -0,0 +1,60 @@ +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['localgov_core.files'] = $base_plugin_definition; + $this->derivatives['localgov_core.files']['parent_id'] = 'entity.media.collection'; + $this->derivatives['localgov_core.files']['title'] = 'Files'; + $this->derivatives['localgov_core.files']['route_name'] = 'view.files.page_1'; + } + } + catch (\Exception $exception) { + // Throw $th;. + } + return parent::getDerivativeDefinitions($base_plugin_definition); + } + +} From 66dc59211ab33e9d0d7427c0d7b514c2e7d83836 Mon Sep 17 00:00:00 2001 From: Marco Pagliarulo Date: Wed, 9 Apr 2025 11:10:50 +0100 Subject: [PATCH 2/4] With the view "files" disabled, localgov_core cause an exception - comment empty catch --- src/Plugin/Derivative/FilesLocalTasks.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Plugin/Derivative/FilesLocalTasks.php b/src/Plugin/Derivative/FilesLocalTasks.php index 7bce38d..05aa333 100644 --- a/src/Plugin/Derivative/FilesLocalTasks.php +++ b/src/Plugin/Derivative/FilesLocalTasks.php @@ -52,7 +52,9 @@ public function getDerivativeDefinitions($base_plugin_definition) { } } catch (\Exception $exception) { - // Throw $th;. + // 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); } From 14697a9a838274d78ee654277822bc06a2a222dd Mon Sep 17 00:00:00 2001 From: ekes Date: Tue, 13 May 2025 13:37:16 +0200 Subject: [PATCH 3/4] The intention of #221 was to move the files tab from the main content menu. Note: This is opinionated administration configuration that probably shouldn't be enforced on users just requiring core or media. It probably wants to live somewhere else. --- .../localgov_media/localgov_media.links.task.yml | 0 modules/localgov_media/localgov_media.module | 10 ++++++++++ .../src}/Plugin/Derivative/FilesLocalTasks.php | 0 3 files changed, 10 insertions(+) rename localgov_core.links.task.yml => modules/localgov_media/localgov_media.links.task.yml (100%) rename {src => modules/localgov_media/src}/Plugin/Derivative/FilesLocalTasks.php (100%) diff --git a/localgov_core.links.task.yml b/modules/localgov_media/localgov_media.links.task.yml similarity index 100% rename from localgov_core.links.task.yml rename to modules/localgov_media/localgov_media.links.task.yml 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/src/Plugin/Derivative/FilesLocalTasks.php b/modules/localgov_media/src/Plugin/Derivative/FilesLocalTasks.php similarity index 100% rename from src/Plugin/Derivative/FilesLocalTasks.php rename to modules/localgov_media/src/Plugin/Derivative/FilesLocalTasks.php From 32c098abad8851d165057812bc7ff0cb62e4c568 Mon Sep 17 00:00:00 2001 From: ekes Date: Tue, 13 May 2025 13:39:26 +0200 Subject: [PATCH 4/4] Link to the files view under media. As per #221. See also #283 issues. The view is supplied by localgov_media so creating the link here too. Probably wants to be in some other LocalGov Admin configuration module really. --- modules/localgov_media/localgov_media.links.task.yml | 3 +-- .../src/Plugin/Derivative/FilesLocalTasks.php | 11 ++++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/localgov_media/localgov_media.links.task.yml b/modules/localgov_media/localgov_media.links.task.yml index c936133..6697c28 100644 --- a/modules/localgov_media/localgov_media.links.task.yml +++ b/modules/localgov_media/localgov_media.links.task.yml @@ -1,3 +1,2 @@ localgov_core.files: - deriver: 'Drupal\localgov_core\Plugin\Derivative\FilesLocalTasks' - weight: 100 + deriver: 'Drupal\localgov_media\Plugin\Derivative\FilesLocalTasks' diff --git a/modules/localgov_media/src/Plugin/Derivative/FilesLocalTasks.php b/modules/localgov_media/src/Plugin/Derivative/FilesLocalTasks.php index 05aa333..b64539e 100644 --- a/modules/localgov_media/src/Plugin/Derivative/FilesLocalTasks.php +++ b/modules/localgov_media/src/Plugin/Derivative/FilesLocalTasks.php @@ -1,6 +1,6 @@ routeProvider->getRouteByName('view.files.page_1')) { - $this->derivatives['localgov_core.files'] = $base_plugin_definition; - $this->derivatives['localgov_core.files']['parent_id'] = 'entity.media.collection'; - $this->derivatives['localgov_core.files']['title'] = 'Files'; - $this->derivatives['localgov_core.files']['route_name'] = '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) {