You are here

protected function MenuMultilingualLinkTreeModifier::hasTranslationOrIsDefaultLang in Menu Multilingual 8

Check link for translation or current language.

Parameters

mixed $link: The menu link plugin instance.

Return value

bool True if link pass a multilingual options.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

1 call to MenuMultilingualLinkTreeModifier::hasTranslationOrIsDefaultLang()
MenuMultilingualLinkTreeModifier::filtersLinks in src/Menu/MenuMultilingualLinkTreeModifier.php
Filter wrapper for either links or menu link tree.

File

src/Menu/MenuMultilingualLinkTreeModifier.php, line 184

Class

MenuMultilingualLinkTreeModifier
Class MenuMultilingualLinkTreeModifier.

Namespace

Drupal\menu_multilingual\Menu

Code

protected function hasTranslationOrIsDefaultLang($link) {
  $current_lang = $this->languageManager
    ->getCurrentLanguage()
    ->getId();
  $result = FALSE;
  $has_translated_label = FALSE;
  $has_translated_content = FALSE;
  if ($this->filterLabels) {
    $has_translated_label = $this
      ->linkIsTranslated($link, $current_lang);
  }
  if ($this->filterContent) {
    $has_translated_content = $this
      ->linkedEntityHasTranslationsOrIsDefault($link, $current_lang);
  }
  if ($this->filterLabels && $this->filterContent) {
    if ($has_translated_label && $has_translated_content) {
      $result = TRUE;
    }
  }
  else {
    if ($this->filterLabels) {
      $result = $has_translated_label;
    }
    elseif ($this->filterContent) {
      $result = $has_translated_content;
    }
  }
  return $result;
}