addExpandedParents example


  public function testAddExpanded() {
    $parameters = new MenuTreeParameters();

    // Verify default value.     $this->assertEquals([]$parameters->expandedParents);

    // Add actual menu link plugin IDs to be expanded.     $parameters->addExpandedParents(['foo', 'bar', 'baz']);
    $this->assertEquals(['foo', 'bar', 'baz']$parameters->expandedParents);

    // Add additional menu link plugin IDs; they should be merged, not replacing     // the old ones.     $parameters->addExpandedParents(['qux', 'quux']);
    $this->assertEquals(['foo', 'bar', 'baz', 'qux', 'quux']$parameters->expandedParents);

    // Add pre-existing menu link plugin IDs; they should not be added again;     // this is a set.     $parameters->addExpandedParents(['bar', 'quux']);
    $this->assertEquals(['foo', 'bar', 'baz', 'qux', 'quux']$parameters->expandedParents);
  }


  /** * {@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;
  }

  /** * {@inheritdoc} */
  
Home | Imprint | This part of the site doesn't use cookies.