comparison core/modules/block/src/Plugin/Derivative/ThemeLocalTask.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 namespace Drupal\block\Plugin\Derivative;
4
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;
9
10 /**
11 * Provides dynamic tabs based on active themes.
12 */
13 class ThemeLocalTask extends DeriverBase implements ContainerDeriverInterface {
14
15 /**
16 * The theme handler.
17 *
18 * @var \Drupal\Core\Extension\ThemeHandlerInterface
19 */
20 protected $themeHandler;
21
22 /**
23 * Constructs a new ThemeLocalTask.
24 *
25 * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
26 * The theme handler.
27 */
28 public function __construct(ThemeHandlerInterface $theme_handler) {
29 $this->themeHandler = $theme_handler;
30 }
31
32 /**
33 * {@inheritdoc}
34 */
35 public static function create(ContainerInterface $container, $base_plugin_id) {
36 return new static(
37 $container->get('theme_handler')
38 );
39 }
40
41 /**
42 * {@inheritdoc}
43 */
44 public function getDerivativeDefinitions($base_plugin_definition) {
45 $default_theme = $this->themeHandler->getDefault();
46
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];
52 }
53 // Default task!
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;
59
60 unset($this->derivatives[$theme_name]['route_parameters']);
61 }
62 }
63 return $this->derivatives;
64 }
65
66 }