You are here

private function MenuMultilingualLinkTreeModifier::linkedEntityHasTranslationsOrIsDefault in Menu Multilingual 8

Check menu item link for translations or current language.

Parameters

mixed $link: The link that will be checked.

string $lang: The language id.

Return value

bool True if link pass a multilingual options.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

1 call to MenuMultilingualLinkTreeModifier::linkedEntityHasTranslationsOrIsDefault()
MenuMultilingualLinkTreeModifier::hasTranslationOrIsDefaultLang in src/Menu/MenuMultilingualLinkTreeModifier.php
Check link for translation or current language.

File

src/Menu/MenuMultilingualLinkTreeModifier.php, line 257

Class

MenuMultilingualLinkTreeModifier
Class MenuMultilingualLinkTreeModifier.

Namespace

Drupal\menu_multilingual\Menu

Code

private function linkedEntityHasTranslationsOrIsDefault($link, $lang) {
  if (empty($link
    ->getRouteName()) || strpos($link
    ->getRouteName(), 'entity.') === FALSE) {
    return TRUE;
  }
  $type = current(array_keys($link
    ->getRouteParameters()));
  $id = $link
    ->getRouteParameters()[$type];
  $result = FALSE;
  if (empty($type) || empty($id)) {
    return $result;
  }
  if (!array_key_exists($type, $this->storages)) {
    $this->storages[$type] = $this->entityTypeManager
      ->getStorage($type);
  }
  $storage = $this->storages[$type];
  $entity = $storage
    ->load($id);
  if ($lang === $entity
    ->get('langcode')) {
    $result = TRUE;
  }
  elseif ($this
    ->entityHasTranslation($entity, $lang)) {
    $result = TRUE;
  }
  $storage
    ->resetCache([
    $id,
  ]);
  return $result;
}