You are here

class MenuLinkTitle in Breadcrumb Manager 8

Class MenuLinkTitle.

@BreadcrumbTitleResolver( id = "menu_link_title", label = @Translation("Menu Link"), description = @Translation("Resolve title from Menu link if exists."), weight = 0 )

@package Drupal\breadcrumb_manager\Plugin\BreadcrumbTitleResolver

Hierarchy

Expanded class hierarchy of MenuLinkTitle

File

src/Plugin/BreadcrumbTitleResolver/MenuLinkTitle.php, line 26

Namespace

Drupal\breadcrumb_manager\Plugin\BreadcrumbTitleResolver
View source
class MenuLinkTitle extends BreadcrumbTitleResolverBase {

  /**
   * The Menu Link Manager service.
   *
   * @var \Drupal\Core\Menu\MenuLinkManagerInterface
   */
  protected $menuLinkManager;

  /**
   * {@inheritdoc}
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, MenuLinkManagerInterface $menu_link_manager) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->menuLinkManager = $menu_link_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('plugin.manager.menu.link'));
  }

  /**
   * {@inheritdoc}
   */
  public function getTitle($path, Request $request, RouteMatchInterface $route_match) {
    $route_name = $route_match
      ->getRouteName();
    $route_parameters = $route_match
      ->getRawParameters()
      ->all();
    $menu_links = $this->menuLinkManager
      ->loadLinksByRoute($route_name, $route_parameters);
    if (empty($menu_links)) {
      return FALSE;
    }
    $titles = [];
    foreach ($menu_links as $menu_link) {
      $menu = $menu_link
        ->getMenuName();
      $titles[$menu] = $menu_link
        ->getTitle();
    }
    return isset($titles['main']) ? $titles['main'] : reset($titles);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BreadcrumbTitleResolverBase::$isActive protected property 1
BreadcrumbTitleResolverBase::isActive public function Is active. Overrides BreadcrumbTitleResolverInterface::isActive 1
BreadcrumbTitleResolverBase::setActive public function Set active. Overrides BreadcrumbTitleResolverInterface::setActive
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
MenuLinkTitle::$menuLinkManager protected property The Menu Link Manager service.
MenuLinkTitle::create public static function Creates an instance of the plugin. Overrides BreadcrumbTitleResolverBase::create
MenuLinkTitle::getTitle public function Get title. Overrides BreadcrumbTitleResolverInterface::getTitle
MenuLinkTitle::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase::__construct
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.