function MenuTreeStorage::delete

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

File

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

Class

MenuTreeStorage
Provides a menu tree storage using the database.

Namespace

Drupal\Core\Menu

Code

public function delete($id) {
    // Children get re-attached to the menu link's parent.
    $item = $this->loadFull($id);
    // It's possible the link is already deleted.
    if ($item) {
        $parent = $item['parent'];
        $children = $this->loadByProperties([
            'parent' => $id,
        ]);
        foreach ($children as $child) {
            $child['parent'] = $parent;
            $this->save($child);
        }
        $this->doDeleteMultiple([
            $id,
        ]);
        $this->updateParentalStatus($item);
        // Many children may have moved.
        $this->resetDefinitions();
        $this->cacheTagsInvalidator
            ->invalidateTags([
            'config:system.menu.' . $item['menu_name'],
        ]);
    }
}

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