You are here

protected function MicrositeMenuItem::getOverrideEntity in Entity Reference Hierarchy 8.2

Same name and namespace in other branches
  1. 3.x modules/entity_hierarchy_microsite/src/Plugin/Menu/MicrositeMenuItem.php \Drupal\entity_hierarchy_microsite\Plugin\Menu\MicrositeMenuItem::getOverrideEntity()

Loads the override entity associated with this menu link.

Return value

\Drupal\entity_hierarchy_microsite\Entity\MicrositeMenuItemOverrideInterface The menu link override

Throws

\Drupal\Component\Plugin\Exception\PluginException If the entity ID and UUID are both invalid or missing.

2 calls to MicrositeMenuItem::getOverrideEntity()
MicrositeMenuItem::getUrlObject in modules/entity_hierarchy_microsite/src/Plugin/Menu/MicrositeMenuItem.php
Returns a URL object containing either the external path or route.
MicrositeMenuItem::updateLink in modules/entity_hierarchy_microsite/src/Plugin/Menu/MicrositeMenuItem.php
Updates the definition values for a menu link.

File

modules/entity_hierarchy_microsite/src/Plugin/Menu/MicrositeMenuItem.php, line 134

Class

MicrositeMenuItem
Defines a class for a menu item based on hierarchy.

Namespace

Drupal\entity_hierarchy_microsite\Plugin\Menu

Code

protected function getOverrideEntity() {
  $storage = $this->entityTypeManager
    ->getStorage('eh_microsite_menu_override');
  if (empty($this->overrideEntity)) {
    if ($items = $storage
      ->loadByProperties([
      'target' => $this
        ->getDerivativeId(),
    ])) {
      $this->overrideEntity = reset($items);
      return $this->overrideEntity;
    }
    $this->overrideEntity = $storage
      ->create([
      'target' => $this
        ->getDerivativeId(),
      'enabled' => $this
        ->isEnabled(),
      'weight' => $this
        ->getWeight(),
      'title' => $this
        ->getTitle(),
      'parent' => $this
        ->getParent(),
    ]);
  }
  return $this->overrideEntity;
}