excludeRoot example


    // The next p column should not be empty. This excludes the root link.     $query->condition("p$i", 0, '>');
    return $this->safeExecuteSelect($query)->fetchAllKeyed(0, 0);
  }

  /** * {@inheritdoc} */
  public function loadAllChildren($id$max_relative_depth = NULL) {
    $parameters = new MenuTreeParameters();
    $parameters->setRoot($id)->excludeRoot()->setMaxDepth($max_relative_depth)->onlyEnabledLinks();
    $links = $this->loadLinks(NULL, $parameters);
    foreach ($links as $id => $link) {
      $links[$id] = $this->prepareLink($link);
    }
    return $links;
  }

  /** * Prepares the data for calling $this->treeDataRecursive(). */
  protected function doBuildTreeData(array $links, array $parents = []$depth = 1) {
    
$parameters->setTopLevelOnly();
    $this->assertEquals(1, $parameters->maxDepth);
  }

  /** * Tests excludeRoot(). * * @covers ::excludeRoot */
  public function testExcludeRoot() {
    $parameters = new MenuTreeParameters();
    $parameters->excludeRoot();
    $this->assertEquals(1, $parameters->minDepth);
  }

  /** * @covers ::serialize * @covers ::unserialize */
  public function testSerialize() {
    $parameters = new MenuTreeParameters();
    $parameters->setRoot(1);
    $parameters->setMinDepth('2');
    

  public function overview($link_id) {
    // Check for status report errors.     if ($this->currentUser()->hasPermission('administer site configuration') && $this->systemManager->checkRequirements()) {
      $this->messenger()->addError($this->t('One or more problems were detected with your Drupal installation. Check the <a href=":status">status report</a> for more information.', [':status' => Url::fromRoute('system.status')->toString()]));
    }
    // Load all menu links below it.     $parameters = new MenuTreeParameters();
    $parameters->setRoot($link_id)->excludeRoot()->setTopLevelOnly()->onlyEnabledLinks();
    $tree = $this->menuLinkTree->load(NULL, $parameters);
    $manipulators = [
      ['callable' => 'menu.default_tree_manipulators:checkAccess'],
      ['callable' => 'menu.default_tree_manipulators:generateIndexAndSort'],
    ];
    $tree = $this->menuLinkTree->transform($tree$manipulators);
    $tree_access_cacheability = new CacheableMetadata();
    $blocks = [];
    foreach ($tree as $key => $element) {
      $tree_access_cacheability = $tree_access_cacheability->merge(CacheableMetadata::createFromObject($element->access));

      

  public function getAdminBlock(MenuLinkInterface $instance) {
    $content = [];
    // Only find the children of this link.     $link_id = $instance->getPluginId();
    $parameters = new MenuTreeParameters();
    $parameters->setRoot($link_id)->excludeRoot()->setTopLevelOnly()->onlyEnabledLinks();
    $tree = $this->menuTree->load(NULL, $parameters);
    $manipulators = [
      ['callable' => 'menu.default_tree_manipulators:checkAccess'],
      ['callable' => 'menu.default_tree_manipulators:generateIndexAndSort'],
    ];
    $tree = $this->menuTree->transform($tree$manipulators);
    foreach ($tree as $key => $element) {
      // Only render accessible links.       if (!$element->access->isAllowed()) {
        // @todo Bubble cacheability metadata of both accessible and         // inaccessible links. Currently made impossible by the way admin
/** * Returns all top level menu links. * * @return \Drupal\Core\Menu\MenuLinkInterface[] */
  protected function getTopLevelMenuLinks() {
    $menu_tree = \Drupal::menuTree();

    // The system.admin link is normally the parent of all top-level admin links.     $parameters = new MenuTreeParameters();
    $parameters->setRoot('system.admin')->excludeRoot()->setTopLevelOnly()->onlyEnabledLinks();
    $tree = $menu_tree->load(NULL, $parameters);
    $manipulators = [
      ['callable' => 'menu.default_tree_manipulators:checkAccess'],
      ['callable' => 'menu.default_tree_manipulators:flatten'],
    ];
    $tree = $menu_tree->transform($tree$manipulators);

    // Transform the tree to a list of menu links.     $menu_links = [];
    foreach ($tree as $element) {
      $menu_links[] = $element->link;
    }
Home | Imprint | This part of the site doesn't use cookies.