class Wiki in Freelinking 4.0.x
Same name and namespace in other branches
- 8.3 src/Plugin/freelinking/Wiki.php \Drupal\freelinking\Plugin\freelinking\Wiki
Freelinking wiki plugin implements wikipedia amongst other plugins.
Plugin annotation
@Freelinking(
id = "wiki",
title = @Translation("Wiki"),
weight = 0,
hidden = false,
settings = { }
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\freelinking\Plugin\FreelinkingPluginBase implements FreelinkingPluginInterface
- class \Drupal\freelinking\Plugin\freelinking\Wiki
- class \Drupal\freelinking\Plugin\FreelinkingPluginBase implements FreelinkingPluginInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of Wiki
1 file declares its use of Wiki
- WikiTest.php in tests/
src/ Unit/ Plugin/ freelinking/ WikiTest.php
1 string reference to 'Wiki'
- WikiTest::getPlugin in tests/
src/ Unit/ Plugin/ freelinking/ WikiTest.php - Get the plugin instance.
File
- src/
Plugin/ freelinking/ Wiki.php, line 19
Namespace
Drupal\freelinking\Plugin\freelinkingView source
class Wiki extends FreelinkingPluginBase {
/**
* A map of wiki abbreviations to full names.
*
* @var array
*/
protected $wikiMap = [
'wp' => 'wikipedia',
'wq' => 'wikiquote',
'wt' => 'wiktionary',
'wn' => 'wikinews',
'ws' => 'wikisource',
'wb' => 'wikibooks',
];
/**
* {@inheritdoc}
*/
public function getTip() {
// @todo Decide to split into multiple plugins for Wikipedia/Wikiquote here.
return $this
->t('Click to view a wiki page.');
}
/**
* {@inheritdoc}
*/
public function getIndicator() {
return '/w((ikipedia|p)|(ikiquote|q)|(iktionary|t)|(ikinews|n)|(ikisource|s)|(ikibooks|b))?$/A';
}
/**
* {@inheritdoc}
*/
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(),
],
];
}
/**
* Get the wiki name from the indicator string.
*
* @param string $indicator
* The indicator string used.
*
* @return string
* The full wiki name.
*/
protected function getWikiFromIndicator($indicator) {
$ret = '';
if (preg_match($this
->getIndicator(), $indicator, $matches)) {
if (strlen($matches[0]) === 2) {
$ret = $this->wikiMap[$matches[0]];
}
else {
// The indicator is the full wiki name.
$ret = $matches[0];
}
}
return $ret;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
FreelinkingPluginBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
|
FreelinkingPluginBase:: |
public | function |
Gets default configuration for this plugin. Overrides ConfigurableInterface:: |
6 |
FreelinkingPluginBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
1 |
FreelinkingPluginBase:: |
public | function |
Get the failover plugin ID (if applicable). Overrides FreelinkingPluginInterface:: |
1 |
FreelinkingPluginBase:: |
public | function |
Determine if the plugin is built-in (always on). Overrides FreelinkingPluginInterface:: |
|
FreelinkingPluginBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
FreelinkingPluginBase:: |
public | function |
Plugin configuration form. Overrides FreelinkingPluginInterface:: |
6 |
MessengerTrait:: |
protected | property | The messenger. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
2 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginBase:: |
public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | 98 |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
Wiki:: |
protected | property | A map of wiki abbreviations to full names. | |
Wiki:: |
public | function |
Build a link with the plugin. Overrides FreelinkingPluginInterface:: |
|
Wiki:: |
public | function |
A regular expression string to indicate what to replace for this plugin. Overrides FreelinkingPluginInterface:: |
|
Wiki:: |
public | function |
Provides tips for this freelinking plugin. Overrides FreelinkingPluginInterface:: |
|
Wiki:: |
protected | function | Get the wiki name from the indicator string. |