You are here

protected function MenuTreeStorage::updateParentalStatus in Drupal 9

Same name and namespace in other branches
  1. 8 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
Deletes a menu link definition from the storage.
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 613

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();
  }
}