You are here

public function Menu::convertLinkItemToLink in Helper 8

Convert a link field item into a link.

Parameters

\Drupal\link\Plugin\Field\FieldType\LinkItem $item: The link field item to convert.

Return value

\Drupal\Core\Link The link.

1 call to Menu::convertLinkItemToLink()
Menu::convertLinkItemsToMenuLinks in src/Menu.php
Convert a link field to an array of menu links.

File

src/Menu.php, line 255

Class

Menu
Provides helpers working with menus and menu links.

Namespace

Drupal\helper

Code

public function convertLinkItemToLink(LinkItem $item) {

  // Render the link item using the default formatter, because the title may
  // contain tokens.
  $item_build = $item
    ->view();

  // Create a link object from the rendered item.
  return Link::fromTextAndUrl($item_build['#title'], $item_build['#url']);
}