setMinDepth example

'Level 2 Item 1',
            ],
            'Level 1 Item 0',
            [
                // Test setMaxString:                 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
                'SHORT',
            ],
        ];

        $cloner = new VarCloner();
        $cloner->setMinDepth(2);
        $cloner->setMaxItems(5);
        $cloner->setMaxString(20);
        $clone = $cloner->cloneVar($data);

        $expected = <<<EOTXT Symfony\Component\VarDumper\Cloner\Data Object ( [data:Symfony\Component\VarDumper\Cloner\Data:private] => Array ( [0] => Array ( [0] => Array ( [2] => 1 ) ) [1] => Array ( [0] => Array ( [2] => 2 ) [1] => Array ( [2] => 3 ) [2] => Array ( [2] => 4 ) [3] => Level 1 Item 0 [4] => Array ( [2] => 5 ) ) [2] => Array ( [0] => Array ( [2] => 6 ) [1] => Array ( [0] => 2 [1] => 7 ) [2] => Array ( [0] => 1 [2] => 0 ) ) [3] => Array ( [0] => Array ( [0] => 1 [2] => 0 ) [1] => Level 2 Item 0 ) [4] => Array ( [0] => Level 2 Item 1 ) [5] => Array ( [0] => Symfony\Component\VarDumper\Cloner\Stub Object ( [type] => 2 [class] => 2 [value] => ABCDEFGHIJKLMNOPQRST [cut] => 6 [handle] => 0 [refCount] => 0 [position] => 0 [attr] => Array ( ) ) [1] => SHORT ) [6] => Array ( [0] => Level 3 Item 0 [1] => Level 3 Item 1 [2] => Level 3 Item 2 [3] => Level 3 Item 3 ) [7] => Array ( [999] => Level 3 Item 4 ) ) [position:Symfony\Component\VarDumper\Cloner\Data:private] => 0 [key:Symfony\Component\VarDumper\Cloner\Data:private] => 0 [maxDepth:Symfony\Component\VarDumper\Cloner\Data:private] => 20 [maxItemsPerDepth:Symfony\Component\VarDumper\Cloner\Data:private] => -1 [useRefHandles:Symfony\Component\VarDumper\Cloner\Data:private] => -1 [context:Symfony\Component\VarDumper\Cloner\Data:private] => Array ( ) )

  public static function preRenderAdministrationTray(array $element) {
    $menu_tree = \Drupal::service('toolbar.menu_tree');
    // Load the administrative menu. The first level is the "Administration"     // link. In order to load the children of that link, start and end on the     // second level.     $parameters = new MenuTreeParameters();
    $parameters->setMinDepth(2)->setMaxDepth(2)->onlyEnabledLinks();
    // @todo Make the menu configurable in https://www.drupal.org/node/1869638.     $tree = $menu_tree->load('admin', $parameters);
    $manipulators = [
      ['callable' => 'menu.default_tree_manipulators:checkAccess'],
      ['callable' => 'menu.default_tree_manipulators:generateIndexAndSort'],
      ['callable' => 'toolbar_menu_navigation_links'],
    ];
    $tree = $menu_tree->transform($tree$manipulators);
    $element['administration_menu'] = $menu_tree->build($tree);
    return $element;
  }

  
$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     // is non-zero, it indicates the number of levels that must be displayed.     // Hence this is a relative depth that we must convert to an actual     // (absolute) depth, that may never exceed the maximum depth.     if ($depth > 0) {
      $parameters->setMaxDepth(min($level + $depth - 1, $this->menuTree->maxDepth()));
    }

    // For menu blocks with start level greater than 1, only show menu items     // from the current active trail. Adjust the root according to the current     // position in the menu in order to determine if we can show the subtree.
return $data;
  }

  /** * Tests setMinDepth(). * * @covers ::setMinDepth * @dataProvider providerTestSetMinDepth */
  public function testSetMinDepth($min_depth$expected) {
    $parameters = new MenuTreeParameters();
    $parameters->setMinDepth($min_depth);
    $this->assertEquals($expected$parameters->minDepth);
  }

  /** * Tests addExpandedParents(). * * @covers ::addExpandedParents */
  public function testAddExpanded() {
    $parameters = new MenuTreeParameters();

    

  protected function loadMenuTree(MenuInterface $menu) : array {
    $parameters = new MenuTreeParameters();
    $parameters->onlyEnabledLinks();
    $parameters->setMinDepth(0);
    $tree = $this->menuTree->load($menu->id()$parameters);
    $manipulators = [
      ['callable' => 'menu.default_tree_manipulators:checkAccess'],
      ['callable' => 'menu.default_tree_manipulators:generateIndexAndSort'],
    ];
    return $this->menuTree->transform($tree$manipulators);
  }

}

  public function excludeRoot() {
    $this->setMinDepth(1);
    return $this;
  }

  /** * {@inheritdoc} */
  public function serialize() {
    return serialize($this->__serialize());
  }

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