Builtin.php in Freelinking 8.3
File
src/Plugin/freelinking/Builtin.php
View source
<?php
namespace Drupal\freelinking\Plugin\freelinking;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\freelinking\Plugin\FreelinkingPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
class Builtin extends FreelinkingPluginBase implements ContainerFactoryPluginInterface {
protected $account;
public function __construct(array $configuration, $plugin_id, $plugin_definition, AccountProxyInterface $account) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->account = $account;
}
public function getTip() {
return $this
->t('Redact, show text only, or display the indicator');
}
public function getIndicator() {
return '/^(showtext|nowiki|redact)$/';
}
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,
];
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('current_user'));
}
}