TotalControlMenuLink.php in Total Control Admin Dashboard 3.0.x
File
src/Plugin/Derivative/TotalControlMenuLink.php
View source
<?php
namespace Drupal\total_control\Plugin\Derivative;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class TotalControlMenuLink extends DeriverBase implements ContainerDeriverInterface {
use StringTranslationTrait;
protected $entityTypeManager;
public function __construct($base_plugin_id, EntityTypeManagerInterface $entity_type_manager, TranslationInterface $string_translation) {
$this->entityTypeManager = $entity_type_manager;
$this
->setStringTranslation($string_translation);
}
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($base_plugin_id, $container
->get('entity_type.manager'), $container
->get('string_translation'));
}
public function getDerivativeDefinitions($base_plugin_definition) {
$router = \Drupal::service('router.route_provider');
if (!empty($router
->getRoutesByNames([
'page_manager.page_view_total_control_dashboard_total_control_dashboard-http_status_code-0',
]))) {
$links['system.total_control_dashboard'] = [
'title' => $this
->t('Dashboard'),
'route_name' => 'page_manager.page_view_total_control_dashboard_total_control_dashboard-http_status_code-0',
'parent' => 'system.admin',
'weight' => '-20',
] + $base_plugin_definition;
return $links;
}
return [];
}
}