function MenuTreeStorage::updateParentalStatus

Same name in other branches
  1. 9 core/lib/Drupal/Core/Menu/MenuTreeStorage.php \Drupal\Core\Menu\MenuTreeStorage::updateParentalStatus()
  2. 8.9.x core/lib/Drupal/Core/Menu/MenuTreeStorage.php \Drupal\Core\Menu\MenuTreeStorage::updateParentalStatus()
  3. 11.x core/lib/Drupal/Core/Menu/MenuTreeStorage.php \Drupal\Core\Menu\MenuTreeStorage::updateParentalStatus()

Sets has_children for the link's parent if it has visible children.

Parameters

array $link: The link to get a parent ID from.

2 calls to MenuTreeStorage::updateParentalStatus()
MenuTreeStorage::delete in core/lib/Drupal/Core/Menu/MenuTreeStorage.php
MenuTreeStorage::doSave in core/lib/Drupal/Core/Menu/MenuTreeStorage.php
Saves a link without clearing caches.

File

core/lib/Drupal/Core/Menu/MenuTreeStorage.php, line 592

Class

MenuTreeStorage
Provides a menu tree storage using the database.

Namespace

Drupal\Core\Menu

Code

protected function updateParentalStatus(array $link) {
    // If parent is empty, there is nothing to update.
    if (!empty($link['parent'])) {
        // Check if at least one visible child exists in the table.
        $query = $this->connection
            ->select($this->table, NULL, $this->options);
        $query->addExpression('1');
        $query->range(0, 1);
        $query->condition('menu_name', $link['menu_name'])
            ->condition('parent', $link['parent'])
            ->condition('enabled', 1);
        $parent_has_children = (bool) $query->execute()
            ->fetchField() ? 1 : 0;
        $this->connection
            ->update($this->table, $this->options)
            ->fields([
            'has_children' => $parent_has_children,
        ])
            ->condition('id', $link['parent'])
            ->execute();
    }
}

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