You are here

protected function MenuBlock::getLinkTitleFromLink in Menu Block 8

Gets the title of a given menu item ID.

Parameters

string $link_id: The menu item ID.

Return value

string|null The menu item title or NULL if the given menu item can't be found.

4 calls to MenuBlock::getLinkTitleFromLink()
MenuBlock::getActiveItemTitle in src/Plugin/Block/MenuBlock.php
Gets the active menu item's title.
MenuBlock::getActiveTrailParentTitle in src/Plugin/Block/MenuBlock.php
Gets the title of the parent of the active menu item.
MenuBlock::getActiveTrailRootTitle in src/Plugin/Block/MenuBlock.php
Gets the current menu item's root menu item title.
MenuBlock::getFixedMenuItemTitle in src/Plugin/Block/MenuBlock.php
Gets the title of a fixed parent item.

File

src/Plugin/Block/MenuBlock.php, line 518

Class

MenuBlock
Provides an extended Menu block.

Namespace

Drupal\menu_block\Plugin\Block

Code

protected function getLinkTitleFromLink($link_id) {
  $parameters = new MenuTreeParameters();
  $menu = $this->menuTree
    ->load($this
    ->getDerivativeId(), $parameters);
  $link = $this
    ->findLinkInTree($menu, $link_id);
  if ($link) {
    if ($this->configuration['label_link']) {
      $block_link = Link::fromTextAndUrl($link->link
        ->getTitle(), $link->link
        ->getUrlObject())
        ->toString();
      return Markup::create($block_link);
    }
    return $link->link
      ->getTitle();
  }
}