Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\block\Plugin\Derivative;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Component\Plugin\Derivative\DeriverBase;
|
Chris@0
|
6 use Drupal\Core\Extension\ThemeHandlerInterface;
|
Chris@0
|
7 use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
|
Chris@0
|
8 use Symfony\Component\DependencyInjection\ContainerInterface;
|
Chris@0
|
9
|
Chris@0
|
10 /**
|
Chris@0
|
11 * Provides dynamic tabs based on active themes.
|
Chris@0
|
12 */
|
Chris@0
|
13 class ThemeLocalTask extends DeriverBase implements ContainerDeriverInterface {
|
Chris@0
|
14
|
Chris@0
|
15 /**
|
Chris@0
|
16 * The theme handler.
|
Chris@0
|
17 *
|
Chris@0
|
18 * @var \Drupal\Core\Extension\ThemeHandlerInterface
|
Chris@0
|
19 */
|
Chris@0
|
20 protected $themeHandler;
|
Chris@0
|
21
|
Chris@0
|
22 /**
|
Chris@0
|
23 * Constructs a new ThemeLocalTask.
|
Chris@0
|
24 *
|
Chris@0
|
25 * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
|
Chris@0
|
26 * The theme handler.
|
Chris@0
|
27 */
|
Chris@0
|
28 public function __construct(ThemeHandlerInterface $theme_handler) {
|
Chris@0
|
29 $this->themeHandler = $theme_handler;
|
Chris@0
|
30 }
|
Chris@0
|
31
|
Chris@0
|
32 /**
|
Chris@0
|
33 * {@inheritdoc}
|
Chris@0
|
34 */
|
Chris@0
|
35 public static function create(ContainerInterface $container, $base_plugin_id) {
|
Chris@0
|
36 return new static(
|
Chris@0
|
37 $container->get('theme_handler')
|
Chris@0
|
38 );
|
Chris@0
|
39 }
|
Chris@0
|
40
|
Chris@0
|
41 /**
|
Chris@0
|
42 * {@inheritdoc}
|
Chris@0
|
43 */
|
Chris@0
|
44 public function getDerivativeDefinitions($base_plugin_definition) {
|
Chris@0
|
45 $default_theme = $this->themeHandler->getDefault();
|
Chris@0
|
46
|
Chris@0
|
47 foreach ($this->themeHandler->listInfo() as $theme_name => $theme) {
|
Chris@0
|
48 if ($this->themeHandler->hasUi($theme_name)) {
|
Chris@0
|
49 $this->derivatives[$theme_name] = $base_plugin_definition;
|
Chris@0
|
50 $this->derivatives[$theme_name]['title'] = $theme->info['name'];
|
Chris@0
|
51 $this->derivatives[$theme_name]['route_parameters'] = ['theme' => $theme_name];
|
Chris@0
|
52 }
|
Chris@0
|
53 // Default task!
|
Chris@0
|
54 if ($default_theme == $theme_name) {
|
Chris@0
|
55 $this->derivatives[$theme_name]['route_name'] = $base_plugin_definition['parent_id'];
|
Chris@0
|
56 // Emulate default logic because without the base plugin id we can't
|
Chris@0
|
57 // change the base_route.
|
Chris@0
|
58 $this->derivatives[$theme_name]['weight'] = -10;
|
Chris@0
|
59
|
Chris@0
|
60 unset($this->derivatives[$theme_name]['route_parameters']);
|
Chris@0
|
61 }
|
Chris@0
|
62 }
|
Chris@0
|
63 return $this->derivatives;
|
Chris@0
|
64 }
|
Chris@0
|
65
|
Chris@0
|
66 }
|