You are here

public function MenuBuilder::updateSubMenuItem in Context 8.4

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

Updates 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 70

Class

MenuBuilder
Implements the MenuBuilder class.

Namespace

Drupal\context_ui

Code

public function updateSubMenuItem(Context $entity) {
  $result = $this->menuLinkManager
    ->loadLinksByRoute('entity.context.edit_form', [
    'context' => $entity
      ->id(),
  ]);
  if (!empty($result)) {
    foreach ($result as $id => $instance) {
      if (strpos($id, 'menu_link_content:') === 0) {
        $instance
          ->updateLink([
          'title' => $entity
            ->getLabel(),
          'link' => $this
            ->getUriString($entity),
        ], TRUE);
      }
    }
    $this->menuLinkManager
      ->rebuild();
  }
  else {
    $this
      ->addSubMenuItem($entity);
  }
}