You are here

class StyleguideLocalTasks in Style Guide 8

Same name and namespace in other branches
  1. 2.x src/Plugin/Derivative/StyleguideLocalTasks.php \Drupal\styleguide\Plugin\Derivative\StyleguideLocalTasks

Styleguide local tasks.

Hierarchy

Expanded class hierarchy of StyleguideLocalTasks

1 string reference to 'StyleguideLocalTasks'
styleguide.links.task.yml in ./styleguide.links.task.yml
styleguide.links.task.yml

File

src/Plugin/Derivative/StyleguideLocalTasks.php, line 14

Namespace

Drupal\styleguide\Plugin\Derivative
View source
class StyleguideLocalTasks extends DeriverBase implements ContainerDeriverInterface {

  /**
   * The configuration object factory.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * The theme handler.
   *
   * @var \Drupal\Core\Extension\ThemeHandlerInterface
   */
  protected $themeHandler;

  /**
   * StyleguideLocalTasks constructor.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The Drupal config factory.
   * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
   *   The Drupal theme habdler.
   */
  public function __construct(ConfigFactoryInterface $config_factory, ThemeHandlerInterface $theme_handler) {
    $this->configFactory = $config_factory;
    $this->themeHandler = $theme_handler;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, $base_plugin_id) {
    return new static($container
      ->get('config.factory'), $container
      ->get('theme_handler'));
  }

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $default_theme = $this->configFactory
      ->get('system.theme')
      ->get('default');
    $themes = $this->themeHandler
      ->rebuildThemeData();
    $weight = 0;
    foreach ($themes as &$theme) {
      if (!empty($theme->info['hidden'])) {
        continue;
      }
      if ($theme->status) {
        $route_name = 'styleguide.' . $theme
          ->getName();
        $this->derivatives[$route_name] = $base_plugin_definition + [
          'title' => $theme->info['name'],
          'route_name' => $route_name,
          'parent_id' => 'styleguide.page',
          'weight' => $weight++,
        ];
        if ($default_theme == $theme
          ->getName()) {
          $this->derivatives[$route_name]['route_name'] = 'styleguide.page';
        }
      }
    }
    return $this->derivatives;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeriverBase::$derivatives protected property List of derivative definitions. 1
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
StyleguideLocalTasks::$configFactory protected property The configuration object factory.
StyleguideLocalTasks::$themeHandler protected property The theme handler.
StyleguideLocalTasks::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
StyleguideLocalTasks::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
StyleguideLocalTasks::__construct public function StyleguideLocalTasks constructor.