3 namespace Drupal\block\Plugin\Derivative;
5 use Drupal\Component\Plugin\Derivative\DeriverBase;
6 use Drupal\Core\Extension\ThemeHandlerInterface;
7 use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
8 use Symfony\Component\DependencyInjection\ContainerInterface;
11 * Provides dynamic tabs based on active themes.
13 class ThemeLocalTask extends DeriverBase implements ContainerDeriverInterface {
18 * @var \Drupal\Core\Extension\ThemeHandlerInterface
20 protected $themeHandler;
23 * Constructs a new ThemeLocalTask.
25 * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
28 public function __construct(ThemeHandlerInterface $theme_handler) {
29 $this->themeHandler = $theme_handler;
35 public static function create(ContainerInterface $container, $base_plugin_id) {
37 $container->get('theme_handler')
44 public function getDerivativeDefinitions($base_plugin_definition) {
45 $default_theme = $this->themeHandler->getDefault();
47 foreach ($this->themeHandler->listInfo() as $theme_name => $theme) {
48 if ($this->themeHandler->hasUi($theme_name)) {
49 $this->derivatives[$theme_name] = $base_plugin_definition;
50 $this->derivatives[$theme_name]['title'] = $theme->info['name'];
51 $this->derivatives[$theme_name]['route_parameters'] = ['theme' => $theme_name];
54 if ($default_theme == $theme_name) {
55 $this->derivatives[$theme_name]['route_name'] = $base_plugin_definition['parent_id'];
56 // Emulate default logic because without the base plugin id we can't
57 // change the base_route.
58 $this->derivatives[$theme_name]['weight'] = -10;
60 unset($this->derivatives[$theme_name]['route_parameters']);
63 return $this->derivatives;