DynamicLocalTasks.php in Thunder 8.5
File
modules/thunder_article/src/Plugin/Derivative/DynamicLocalTasks.php
View source
<?php
namespace Drupal\thunder_article\Plugin\Derivative;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\Core\Routing\RouteProviderInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class DynamicLocalTasks extends DeriverBase implements ContainerDeriverInterface {
use StringTranslationTrait;
protected $moduleHandler;
protected $routeProvider;
protected $configFactory;
public function __construct(TranslationInterface $string_translation, ModuleHandlerInterface $module_handler, RouteProviderInterface $route_provider, ConfigFactoryInterface $config_factory) {
$this->stringTranslation = $string_translation;
$this->moduleHandler = $module_handler;
$this->routeProvider = $route_provider;
$this->configFactory = $config_factory;
}
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($container
->get('string_translation'), $container
->get('module_handler'), $container
->get('router.route_provider'), $container
->get('config.factory'));
}
public function getDerivativeDefinitions($base_plugin_definition) {
if ($this->moduleHandler
->moduleExists('content_lock') && $this->routeProvider
->getRoutesByNames([
'view.locked_content.page_1',
])) {
$this->derivatives["thunder_article.content_lock"] = [
'route_name' => "view.locked_content.page_1",
'title' => $this
->t('Locked content'),
'parent_id' => "system.admin_content",
'weight' => 2,
] + $base_plugin_definition;
}
if ($this->moduleHandler
->moduleExists('access_unpublished') && $this->routeProvider
->getRoutesByNames([
'access_unpublished.access_token.list',
])) {
$this->derivatives["thunder_article.access_unpublished"] = [
'route_name' => "access_unpublished.access_token.list",
'title' => $this
->t('Unpublished access'),
'parent_id' => "system.admin_content",
'weight' => 4,
] + $base_plugin_definition;
}
return $this->derivatives;
}
}