You are here

private function MenuMultilingualLinkTreeModifier::isTranslatedMenuLinkContentMultilingual in Menu Multilingual 8

Check if link is MenuLinkContent & translated.

Parameters

mixed $link: The link that will be checked.

string $lang: The language id.

Return value

bool True if link is MenuLinkContent and has translation.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

1 call to MenuMultilingualLinkTreeModifier::isTranslatedMenuLinkContentMultilingual()
MenuMultilingualLinkTreeModifier::linkIsTranslated in src/Menu/MenuMultilingualLinkTreeModifier.php
Check link for translations or current language.

File

src/Menu/MenuMultilingualLinkTreeModifier.php, line 366

Class

MenuMultilingualLinkTreeModifier
Class MenuMultilingualLinkTreeModifier.

Namespace

Drupal\menu_multilingual\Menu

Code

private function isTranslatedMenuLinkContentMultilingual($link, $lang) {
  $result = FALSE;
  if (!$link instanceof MenuLinkContent) {
    return NULL;
  }
  $storage = $this->storages['menu_link_content'];
  if (!empty($link
    ->getPluginDefinition()['metadata']['entity_id'])) {
    $entity_id = $link
      ->getPluginDefinition()['metadata']['entity_id'];
    $entity = $storage
      ->load($entity_id);
    $langcode_key = $entity
      ->getEntityType()
      ->getKey('langcode');
    if ($lang == $entity
      ->get($langcode_key)->value) {
      $result = TRUE;
    }
    elseif ($this
      ->entityHasTranslation($entity, $lang)) {
      $result = TRUE;
    }
    $storage
      ->resetCache([
      $entity_id,
    ]);
  }
  return $result;
}