You are here

public function Menu::convertLinkToMenuLink in Helper 8

Convert a link into a menu link.

Parameters

\Drupal\Core\Link $link: The link to convert.

Return value

array The menu link, ready for rendering in a menu.

2 calls to Menu::convertLinkToMenuLink()
Menu::convertLinkItemsToMenuLinks in src/Menu.php
Convert a link field to an array of menu links.
Menu::convertLinksToMenuLinks in src/Menu.php
Convert a link field to an array of menu links.

File

src/Menu.php, line 183

Class

Menu
Provides helpers working with menus and menu links.

Namespace

Drupal\helper

Code

public function convertLinkToMenuLink(Link $link) {

  // @todo Should this abstracted to its own formatter for link field types?
  return [
    'is_expanded' => FALSE,
    'is_collapsed' => FALSE,
    'in_active_trail' => FALSE,
    'attributes' => new Attribute(),
    'title' => $link
      ->getText(),
    'url' => $link
      ->getUrl(),
    'below' => [],
    // @todo This should be a MenuLinkContent object.
    'original_link' => NULL,
  ];
}