You are here

public function MenuBuilder::deleteSubMenuItem in Context 8

Same name and namespace in other branches
  1. 8.4 modules/context_ui/src/MenuBuilder.php \Drupal\context_ui\MenuBuilder::deleteSubMenuItem()

Deletes the submenu item of the $entity item.

Parameters

\Drupal\context\Entity\Context $entity The given entity item.:

File

modules/context_ui/src/MenuBuilder.php, line 95

Class

MenuBuilder
Implements the MenuBuilder class, which configures and updates the submenu context items

Namespace

Drupal\context_ui

Code

public function deleteSubMenuItem(Context $entity) {
  $result = $this->menuLinkManager
    ->loadLinksByRoute('entity.context.edit_form', [
    'context' => $entity
      ->id(),
  ]);
  if (!empty($result)) {
    foreach ($result as $id => $instance) {
      if ($instance
        ->isDeletable() && strpos($id, 'menu_link_content:') === 0) {
        $instance
          ->deleteLink();
        $this->menuLinkManager
          ->rebuild();
      }
    }
  }
}