ab9f87d949618ae6e32d4be61dd4db47078e1c40
[yaffs-website] / web / core / modules / system / src / Plugin / Derivative / ThemeLocalTask.php
1 <?php
2
3 namespace Drupal\system\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 instance.
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     foreach ($this->themeHandler->listInfo() as $theme_name => $theme) {
46       if ($this->themeHandler->hasUi($theme_name)) {
47         $this->derivatives[$theme_name] = $base_plugin_definition;
48         $this->derivatives[$theme_name]['title'] = $theme->info['name'];
49         $this->derivatives[$theme_name]['route_parameters'] = ['theme' => $theme_name];
50       }
51     }
52     return $this->derivatives;
53   }
54
55 }