Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions localgov_core.links.task.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ dependencies:
module:
- entity_usage
- image
- localgov_core
- media
- user
id: media
Expand Down
2 changes: 2 additions & 0 deletions modules/localgov_media/localgov_media.links.task.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
localgov_core.files:
deriver: 'Drupal\localgov_media\Plugin\Derivative\FilesLocalTasks'
10 changes: 10 additions & 0 deletions modules/localgov_media/localgov_media.module
Original file line number Diff line number Diff line change
Expand Up @@ -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().
*/
Expand Down
63 changes: 63 additions & 0 deletions modules/localgov_media/src/Plugin/Derivative/FilesLocalTasks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace Drupal\localgov_media\Plugin\Derivative;

use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Routing\RouteProviderInterface;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Provides local task for files view under entity media collection.
*/
class FilesLocalTasks extends DeriverBase implements ContainerDeriverInterface {

/**
* The route provider.
*
* @var \Drupal\Core\Routing\RouteProviderInterface
*/
protected $routeProvider;

/**
* Constructs a FilesLocalTasks instance.
*
* @param \Drupal\Core\Routing\RouteProviderInterface $route_provider
* The route provider.
*/
public function __construct(RouteProviderInterface $route_provider) {
$this->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);
}

}