context-8.x-4.x-dev/src/ContextMenuActiveTrail.php

src/ContextMenuActiveTrail.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
 
namespace Drupal\context;
 
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Lock\LockBackendInterface;
use Drupal\Core\Menu\MenuActiveTrail;
use Drupal\Core\Menu\MenuLinkManagerInterface;
use Drupal\Core\Routing\RouteMatchInterface;
 
/**
 * Extend the MenuActiveTrail class.
 */
class ContextMenuActiveTrail extends MenuActiveTrail {
 
  /**
   * The Context module context manager.
   *
   * @var \Drupal\context\ContextManager
   */
  protected $contextManager;
 
  /**
   * {@inheritdoc}
   */
  public function __construct(MenuLinkManagerInterface $menu_link_manager, RouteMatchInterface $route_match, CacheBackendInterface $cache, LockBackendInterface $lock, ContextManager $context_manager) {
    parent::__construct($menu_link_manager, $route_match, $cache, $lock);
    $this->contextManager = $context_manager;
  }
 
  /**
   * {@inheritdoc}
   */
  public function getActiveLink($menu_name = NULL) {
    $found = parent::getActiveLink($menu_name);
 
    // Get active reaction of Menu type.
    foreach ($this->contextManager->getActiveReactions('menu') as $reaction) {
      $menu_items = $reaction->execute();
      foreach ($menu_items as $menu_link_content) {
        $menu = strtok($menu_link_content, ':');
        if ($menu == $menu_name) {
          $plugin_id = substr($menu_link_content, strlen($menu) + 1);
          return $this->menuLinkManager->createInstance($plugin_id);
        }
      }
    }
    return $found;
  }
 
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc