8000 With the view "files" disabled, localgov_core cause an exception #283 by ekes · Pull Request #297 · localgovdrupal/localgov_core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

With the view "files" disabled, localgov_core cause an exception #283 #297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: 2.x
Choose a base branch
from
Open
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.

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 \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['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);
}

}
Loading
0