function MenuDevelGenerate::deleteMenus

Same name in other branches
  1. 5.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 271

Class

MenuDevelGenerate
Provides a MenuDevelGenerate plugin.

Namespace

Drupal\devel_generate\Plugin\DevelGenerate

Code

protected function deleteMenus() {
    if ($this->moduleHandler
        ->moduleExists('menu_ui')) {
        $menu_ids = [];
        foreach (menu_ui_get_menus(FALSE) as $menu => $menu_title) {
            if (strpos($menu, 'devel-') === 0) {
                $menu_ids[] = $menu;
            }
        }
        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')
        ->execute();
    if ($link_ids) {
        $links = $this->menuLinkContentStorage
            ->loadMultiple($link_ids);
        $this->menuLinkContentStorage
            ->delete($links);
    }
    return [
        count($menu_ids),
        count($link_ids),
    ];
}