function MenuDevelGenerate::deleteMenus
Same name in other branches
- 4.x devel_generate/src/Plugin/DevelGenerate/MenuDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\MenuDevelGenerate::deleteMenus()
Deletes custom generated menus.
1 call to MenuDevelGenerate::deleteMenus()
- MenuDevelGenerate::generateElements in devel_generate/
src/ Plugin/ DevelGenerate/ MenuDevelGenerate.php - Business logic relating with each DevelGenerate plugin.
File
-
devel_generate/
src/ Plugin/ DevelGenerate/ MenuDevelGenerate.php, line 227
Class
- MenuDevelGenerate
- Provides a MenuDevelGenerate plugin.
Namespace
Drupal\devel_generate\Plugin\DevelGenerateCode
protected function deleteMenus() : array {
$menu_ids = [];
if ($this->moduleHandler
->moduleExists('menu_ui')) {
$all = $this->menuStorage
->loadMultiple();
foreach ($all as $menu) {
if (str_starts_with($menu->id(), 'devel-')) {
$menu_ids[] = $menu->id();
}
}
if ($menu_ids !== []) {
$menus = $this->menuStorage
->loadMultiple($menu_ids);
$this->menuStorage
->delete($menus);
}
}
// Delete menu links in other menus, but generated by devel.
$link_ids = $this->menuLinkContentStorage
->getQuery()
->condition('menu_name', 'devel', '<>')
->condition('link__options', '%' . $this->database
->escapeLike('s:5:"devel";b:1') . '%', 'LIKE')
->accessCheck(FALSE)
->execute();
if ($link_ids) {
$links = $this->menuLinkContentStorage
->loadMultiple($link_ids);
$this->menuLinkContentStorage
->delete($links);
}
return [
count($menu_ids),
count($link_ids),
];
}