You are here

public function Wiki::buildLink in Freelinking 8.3

Same name and namespace in other branches
  1. 4.0.x src/Plugin/freelinking/Wiki.php \Drupal\freelinking\Plugin\freelinking\Wiki::buildLink()

Build a link with the plugin.

Parameters

array $target: The target array with including the following keys:

  • text: The text to display in the URL.
  • indicator: The indicator string.
  • dest: The destination string for the plugin to turn into a URI.
  • tooltip: An optional tooltip.
  • language: A language object.

Return value

array Link array.

Overrides FreelinkingPluginInterface::buildLink

File

src/Plugin/freelinking/Wiki.php, line 53

Class

Wiki
Freelinking wiki plugin implements wikipedia amongst other plugins.

Namespace

Drupal\freelinking\Plugin\freelinking

Code

public function buildLink(array $target) {
  $wikiname = $this
    ->getWikiFromIndicator($target['indicator']);
  $langcode = $target['language']
    ->getId();
  $dest = str_replace(' ', '_', $target['dest']);
  $wikiurl = 'https://' . $langcode . '.' . $wikiname . '.org/wiki/' . $dest;
  return [
    '#type' => 'link',
    '#title' => isset($target['text']) ? $target['text'] : ucwords($wikiname),
    '#url' => Url::fromUri($wikiurl, [
      'language' => $target['language'],
      'absolute' => TRUE,
    ]),
    '#attributes' => [
      'title' => isset($target['tooltip']) ? $target['tooltip'] : $this
        ->getTip(),
    ],
  ];
}