class MenuPositionActiveTrail in Menu Position 8
Menu Position active trail.
Hierarchy
- class \Drupal\Core\Cache\CacheCollector implements CacheCollectorInterface, DestructableInterface
- class \Drupal\Core\Menu\MenuActiveTrail implements MenuActiveTrailInterface
- class \Drupal\menu_position\Menu\MenuPositionActiveTrail
- class \Drupal\Core\Menu\MenuActiveTrail implements MenuActiveTrailInterface
Expanded class hierarchy of MenuPositionActiveTrail
File
- src/
Menu/ MenuPositionActiveTrail.php, line 16
Namespace
Drupal\menu_position\MenuView source
class MenuPositionActiveTrail extends MenuActiveTrail {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Menu position settings.
*
* @var \Drupal\Core\Config\ImmutableConfig
*/
protected $settings;
/**
* Constructs a \Drupal\Core\Menu\MenuActiveTrail object.
*
* @param \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager
* The menu link plugin manager.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* A route match object for finding the active link.
* @param \Drupal\Core\Cache\CacheBackendInterface $cache
* The cache backend service.
* @param \Drupal\Core\Lock\LockBackendInterface $lock
* The lock backend service.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory service.
*/
public function __construct(MenuLinkManagerInterface $menu_link_manager, RouteMatchInterface $route_match, CacheBackendInterface $cache, LockBackendInterface $lock, EntityTypeManagerInterface $entity_type_manager, ConfigFactoryInterface $config_factory) {
parent::__construct($menu_link_manager, $route_match, $cache, $lock);
$this->entityTypeManager = $entity_type_manager;
$this->settings = $config_factory
->get('menu_position.settings');
}
/**
* {@inheritdoc}
*/
public function getActiveLink($menu_name = NULL) {
// Get all the rules.
$query = $this->entityTypeManager
->getStorage('menu_position_rule')
->getQuery();
// Filter on the menu name if there is one.
if (isset($menu_name)) {
$query
->condition('menu_name', $menu_name);
}
$results = $query
->sort('weight')
->execute();
$rules = $this->entityTypeManager
->getStorage('menu_position_rule')
->loadMultiple($results);
// Iterate over the rules.
foreach ($rules as $rule) {
// This rule is active.
if ($rule
->isActive()) {
$menu_link = $this->menuLinkManager
->createInstance($rule
->getMenuLink());
$active_menu_link = NULL;
switch ($this->settings
->get('link_display')) {
case 'child':
// Set this menu link to active.
$active_menu_link = $menu_link;
break;
case 'parent':
$active_menu_link = $this->menuLinkManager
->createInstance($menu_link
->getParent());
break;
case 'none':
$active_menu_link = NULL;
break;
}
return $active_menu_link;
}
}
// Default implementation takes here.
return parent::getActiveLink($menu_name);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CacheCollector:: |
protected | property | The cache backend that should be used. | 1 |
CacheCollector:: |
protected | property | Stores the cache creation time. | |
CacheCollector:: |
protected | property | Flag that indicates of the cache has been invalidated. | |
CacheCollector:: |
protected | property | Indicates if the collected cache was already loaded. | |
CacheCollector:: |
protected | property | The cache id that is used for the cache entry. | |
CacheCollector:: |
protected | property | An array of keys to add to the cache on service termination. | |
CacheCollector:: |
protected | property | An array of keys to remove from the cache on service termination. | |
CacheCollector:: |
protected | property | The lock backend that should be used. | 1 |
CacheCollector:: |
protected | property | Storage for the data itself. | |
CacheCollector:: |
protected | property | A list of tags that are used for the cache entry. | |
CacheCollector:: |
public | function |
Clears the collected cache entry. Overrides CacheCollectorInterface:: |
1 |
CacheCollector:: |
public | function |
Deletes the element. Overrides CacheCollectorInterface:: |
|
CacheCollector:: |
public | function |
Performs destruct operations. Overrides DestructableInterface:: |
|
CacheCollector:: |
public | function |
Gets value from the cache. Overrides CacheCollectorInterface:: |
2 |
CacheCollector:: |
public | function |
Returns whether data exists for this key. Overrides CacheCollectorInterface:: |
1 |
CacheCollector:: |
protected | function | Invalidate the cache. | |
CacheCollector:: |
protected | function | Loads the cache if not already done. | 1 |
CacheCollector:: |
protected | function | Normalizes a cache ID in order to comply with database limitations. | |
CacheCollector:: |
protected | function | Flags an offset value to be written to the persistent cache. | |
CacheCollector:: |
public | function |
Resets the local cache. Overrides CacheCollectorInterface:: |
1 |
CacheCollector:: |
public | function |
Implements \Drupal\Core\Cache\CacheCollectorInterface::set(). Overrides CacheCollectorInterface:: |
1 |
CacheCollector:: |
protected | function | Writes a value to the persistent cache immediately. | 1 |
MenuActiveTrail:: |
protected | property | The menu link plugin manager. | |
MenuActiveTrail:: |
protected | property | The route match object for the current page. | |
MenuActiveTrail:: |
protected | function | Helper method for ::getActiveTrailIds(). | |
MenuActiveTrail:: |
public | function |
This implementation caches all active trail IDs per route match for *all*
menus whose active trails are calculated on that page. This ensures 1 cache
get for all active trails per page load, rather than N. Overrides MenuActiveTrailInterface:: |
|
MenuActiveTrail:: |
protected | function |
Overrides CacheCollector:: |
|
MenuActiveTrail:: |
protected | function |
Overrides CacheCollector:: |
|
MenuPositionActiveTrail:: |
protected | property | The entity type manager. | |
MenuPositionActiveTrail:: |
protected | property | Menu position settings. | |
MenuPositionActiveTrail:: |
public | function |
Fetches a menu link which matches the route name, parameters and menu name. Overrides MenuActiveTrail:: |
|
MenuPositionActiveTrail:: |
public | function |
Constructs a \Drupal\Core\Menu\MenuActiveTrail object. Overrides MenuActiveTrail:: |