Skip to content
Closed
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
4 changes: 1 addition & 3 deletions localgov_core.links.task.yml
Original file line number Diff line number Diff line change
@@ -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
62 changes: 62 additions & 0 deletions src/Plugin/Derivative/FilesLocalTasks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace Drupal\localgov_core\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 \Drupal\localgov_core\Plugin\Derivative\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['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) {
// 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);
}

}
Loading