You are here

public function Builtin::buildLink in Freelinking 8.3

Same name and namespace in other branches
  1. 4.0.x src/Plugin/freelinking/Builtin.php \Drupal\freelinking\Plugin\freelinking\Builtin::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/Builtin.php, line 65

Class

Builtin
Freelinking builtin plugin.

Namespace

Drupal\freelinking\Plugin\freelinking

Code

public function buildLink(array $target) {
  $text = '';
  if ('showtext' === $target['indicator']) {
    $text = $target['text'] ? $target['text'] : $target['dest'];
  }
  elseif ('nowiki' === $target['indicator']) {
    $text .= '[[';
    $text .= $target['text'] ? $target['text'] : $target['dest'];
    $text .= ']]';
  }
  elseif ('redact' === $target['indicator']) {
    if ($this->account
      ->isAuthenticated()) {
      $text = $target['dest'];
    }
    else {
      $text = $target['text'] ? $target['text'] : '******';
    }
  }
  return [
    '#markup' => $text,
  ];
}