You are here

class StyleguideMenuLinks in Style Guide 8

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

Styleguide menu links.

Hierarchy

Expanded class hierarchy of StyleguideMenuLinks

1 string reference to 'StyleguideMenuLinks'
styleguide.links.menu.yml in ./styleguide.links.menu.yml
styleguide.links.menu.yml

File

src/Plugin/Derivative/StyleguideMenuLinks.php, line 13

Namespace

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

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

  /**
   * StyleguideMenuLinks constructor.
   *
   * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
   *   The Drupal theme habdler.
   */
  public function __construct(ThemeHandlerInterface $theme_handler) {
    $this->themeHandler = $theme_handler;
  }

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

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $themes = $this->themeHandler
      ->rebuildThemeData();
    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,
        ];
      }
    }
    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
StyleguideMenuLinks::$themeHandler protected property The theme handler.
StyleguideMenuLinks::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
StyleguideMenuLinks::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
StyleguideMenuLinks::__construct public function StyleguideMenuLinks constructor.