function MenuLinkTreeElement::count

Same name in other branches
  1. 9 core/lib/Drupal/Core/Menu/MenuLinkTreeElement.php \Drupal\Core\Menu\MenuLinkTreeElement::count()
  2. 10 core/lib/Drupal/Core/Menu/MenuLinkTreeElement.php \Drupal\Core\Menu\MenuLinkTreeElement::count()
  3. 11.x core/lib/Drupal/Core/Menu/MenuLinkTreeElement.php \Drupal\Core\Menu\MenuLinkTreeElement::count()

Counts all menu links in the current subtree.

Return value

int The number of menu links in this subtree (one plus the number of menu links in all descendants).

File

core/lib/Drupal/Core/Menu/MenuLinkTreeElement.php, line 116

Class

MenuLinkTreeElement
Provides a value object to model an element in a menu link tree.

Namespace

Drupal\Core\Menu

Code

public function count() {
    $sum = function ($carry, MenuLinkTreeElement $element) {
        return $carry + $element->count();
    };
    return 1 + array_reduce($this->subtree, $sum);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.