protected function MenuLinkStorageController::updateParentalStatus

Checks and updates the 'has_children' property for the parent of a link.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: A menu link entity.

3 calls to MenuLinkStorageController::updateParentalStatus()
MenuLinkStorageController::moveChildren in drupal/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php
Updates the children of a menu link that is being moved.
MenuLinkStorageController::postDelete in drupal/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php
Overrides DatabaseStorageController::postDelete().
MenuLinkStorageController::postSave in drupal/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php
DatabaseStorageController::postSave().

File

drupal/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php, line 430
Contains \Drupal\menu_link\MenuLinkStorageController.

Class

MenuLinkStorageController
Controller class for menu links.

Namespace

Drupal\menu_link

Code

protected function updateParentalStatus(EntityInterface $entity, $exclude = FALSE) {

  // If plid == 0, there is nothing to update.
  if ($entity->plid) {

    // Check if at least one visible child exists in the table.
    $query = \Drupal::entityQuery($this->entityType);
    $query
      ->condition('menu_name', $entity->menu_name)
      ->condition('hidden', 0)
      ->condition('plid', $entity->plid)
      ->count();
    if ($exclude) {
      $query
        ->condition('mlid', $entity
        ->id(), '<>');
    }
    $parent_has_children = (bool) $query
      ->execute() ? 1 : 0;
    $this->database
      ->update('menu_links')
      ->fields(array(
      'has_children' => $parent_has_children,
    ))
      ->condition('mlid', $entity->plid)
      ->execute();
  }
}