You are here

StyleguideMenuLinks.php in Style Guide 2.x

Same filename and directory in other branches
  1. 8 src/Plugin/Derivative/StyleguideMenuLinks.php

File

src/Plugin/Derivative/StyleguideMenuLinks.php
View source
<?php

namespace Drupal\styleguide\Plugin\Derivative;

use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Extension\ThemeHandlerInterface;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Styleguide menu links.
 */
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;
  }

}

Classes

Namesort descending Description
StyleguideMenuLinks Styleguide menu links.