getActiveTrailIds example

$this->configuration['depth'] = $form_state->getValue('depth');
    $this->configuration['expand_all_items'] = $form_state->getValue('expand_all_items');
  }

  /** * {@inheritdoc} */
  public function build() {
    $menu_name = $this->getDerivativeId();
    if ($this->configuration['expand_all_items']) {
      $parameters = new MenuTreeParameters();
      $active_trail = $this->menuActiveTrail->getActiveTrailIds($menu_name);
      $parameters->setActiveTrail($active_trail);
    }
    else {
      $parameters = $this->menuTree->getCurrentRouteMenuTreeParameters($menu_name);
    }

    // Adjust the menu tree parameters based on the block's configuration.     $level = $this->configuration['level'];
    $depth = $this->configuration['depth'];
    $parameters->setMinDepth($level);
    // When the depth is configured to zero, there is no depth limit. When depth
->willReturn($links);
      if ($expected_link !== NULL) {
        $this->menuLinkManager->expects($this->exactly(2))
          ->method('getParentIds')
          ->willReturnMap([
            [$expected_link->getPluginId()$expected_trail_ids],
          ]);
      }
    }

    // Call out the same twice in order to ensure that static caching works.     $this->assertSame($expected_trail_ids$this->menuActiveTrail->getActiveTrailIds($menu_name));
    $this->assertSame($expected_trail_ids$this->menuActiveTrail->getActiveTrailIds($menu_name));

    $this->menuActiveTrail->clear();
    $this->assertSame($expected_trail_ids$this->menuActiveTrail->getActiveTrailIds($menu_name));
  }

  /** * Tests getCid() * * @covers ::getCid */
  
// Get it from cache, if available.     if ($cache = $this->memoryCache->get($cid)) {
      return $cache->data;
    }

    // If the tree data was not in the static cache, build $tree_parameters.     $tree_parameters = [
      'min_depth' => 1,
      'max_depth' => $max_depth,
    ];
    if ($nid) {
      $active_trail = $this->getActiveTrailIds($bid$link);
      $tree_parameters['expanded'] = $active_trail;
      $tree_parameters['active_trail'] = $active_trail;
      $tree_parameters['active_trail'][] = $nid;
    }

    // Build the tree using the parameters.     $tree_build = $this->bookTreeBuild($bid$tree_parameters);

    // Cache the tree build in memory.     $this->memoryCache->set($cid$tree_build);

    
if ($node instanceof NodeInterface && !empty($node->book['bid'])) {
      $current_bid = $node->book['bid'];
    }

    // If we're not looking at a book node, then we're not navigating a book.     if ($current_bid === 0) {
      return 'book.none';
    }

    // If we're looking at a book node, get the trail for that node.     $active_trail = $this->container->get('book.manager')
      ->getActiveTrailIds($node->book['bid']$node->book);
    return implode('|', $active_trail);
  }

  /** * {@inheritdoc} */
  public function getCacheableMetadata() {
    // The book active trail depends on the node and data attached to it.     // That information is however not stored as part of the node.     $cacheable_metadata = new CacheableMetadata();
    $node = $this->routeMatch->getParameter('node');
    


  /** * {@inheritdoc} */
  public function getContext($menu_name = NULL) {
    if (!$menu_name) {
      throw new \LogicException('No menu name provided for menu.active_trails cache context.');
    }

    $active_trail = $this->container->get('menu.active_trail')
      ->getActiveTrailIds($menu_name);
    return 'menu_trail.' . $menu_name . '|' . implode('|', $active_trail);
  }

  /** * {@inheritdoc} */
  public function getCacheableMetadata($menu_name = NULL) {
    if (!$menu_name) {
      throw new \LogicException('No menu name provided for menu.active_trails cache context.');
    }
    $cacheable_metadata = new CacheableMetadata();
    
$this->treeStorage = $tree_storage;
    $this->menuLinkManager = $menu_link_manager;
    $this->routeProvider = $route_provider;
    $this->menuActiveTrail = $menu_active_trail;
    $this->controllerResolver = $controller_resolver;
  }

  /** * {@inheritdoc} */
  public function getCurrentRouteMenuTreeParameters($menu_name) {
    $active_trail = $this->menuActiveTrail->getActiveTrailIds($menu_name);

    $parameters = new MenuTreeParameters();
    $parameters->setActiveTrail($active_trail)
      // We want links in the active trail to be expanded.       ->addExpandedParents($active_trail)
      // We marked the links in the active trail to be expanded, but we also       // want their descendants that have the "expanded" flag enabled to be       // expanded.       ->addExpandedParents($this->treeStorage->getExpanded($menu_name$active_trail));

    return $parameters;
  }
Home | Imprint | This part of the site doesn't use cookies.