You are here

public function FlippyPager::flippy_generate_link in Flippy 8

Helper function to generate link.

Parameters

int $nodeId: Target node ID.

string $label: Target node label.

Return value

array|mixed Link render array.

File

src/FlippyPager.php, line 419

Class

FlippyPager
Defines the flippy pager service.

Namespace

Drupal\flippy

Code

public function flippy_generate_link($nodeId, $label) {
  $token_service = $this->token;
  $language = $this->languageManager
    ->getCurrentLanguage()
    ->getId();
  $url = Url::fromRoute('entity.node.canonical');
  $url
    ->setRouteParameter('node', $nodeId);
  $node_storage = $this->entityTypeManager
    ->getStorage('node');
  $flippyLink = Link::fromTextAndUrl(HTML::decodeEntities($token_service
    ->replace($label, [
    'node' => $node_storage
      ->load($nodeId),
  ], [
    'langcode' => $language,
  ])), $url);
  return $flippyLink
    ->toRenderable();
}