You are here

public function TaxonomyMenuMenuLink::getDescription in Taxonomy menu 8.3

Returns the description of the menu link.

Return value

string The description of the menu link.

Overrides MenuLinkInterface::getDescription

File

src/Plugin/Menu/TaxonomyMenuMenuLink.php, line 112

Class

TaxonomyMenuMenuLink
Defines menu links provided by taxonomy menu.

Namespace

Drupal\taxonomy_menu\Plugin\Menu

Code

public function getDescription() {

  /* @var $link \Drupal\taxonomy\Entity\Term. */
  $link = $this->entityTypeManager
    ->getStorage('taxonomy_term')
    ->load($this->pluginDefinition['metadata']['taxonomy_term_id']);

  // Get the description field name.
  $taxonomy_menu = $this->entityTypeManager
    ->getStorage('taxonomy_menu')
    ->load($this->pluginDefinition['metadata']['taxonomy_menu_id']);
  $description_field_name = !empty($taxonomy_menu) ? $taxonomy_menu
    ->getDescriptionFieldName() : '';
  $language = \Drupal::languageManager()
    ->getCurrentLanguage()
    ->getId();
  if (!empty($link) && $link
    ->hasTranslation($language)) {
    $translation = $link
      ->getTranslation($language);
    if (!empty($translation) && $translation
      ->hasField($description_field_name)) {
      return $translation->{$description_field_name}->value;
    }
  }
  elseif (!empty($link) && $link
    ->hasField($description_field_name)) {
    return $link->{$description_field_name}->value;
  }
}