class LinkShortcode in Shortcode 2.0.x
Same name and namespace in other branches
- 8 shortcode_basic_tags/src/Plugin/Shortcode/LinkShortcode.php \Drupal\shortcode_basic_tags\Plugin\Shortcode\LinkShortcode
Insert div or span around the text with some css classes.
Plugin annotation
@Shortcode(
id = "link",
title = @Translation("Link"),
description = @Translation("Makes an aliased link to the given path.")
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\shortcode\Plugin\ShortcodeBase implements ShortcodeInterface
- class \Drupal\shortcode_basic_tags\Plugin\Shortcode\LinkShortcode
- class \Drupal\shortcode\Plugin\ShortcodeBase implements ShortcodeInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of LinkShortcode
File
- shortcode_basic_tags/
src/ Plugin/ Shortcode/ LinkShortcode.php, line 17
Namespace
Drupal\shortcode_basic_tags\Plugin\ShortcodeView source
class LinkShortcode extends ShortcodeBase {
/**
* {@inheritdoc}
*/
public function process(array $attributes, $text, $langcode = Language::LANGCODE_NOT_SPECIFIED) {
// Merge with default attributes.
$attributes = $this
->getAttributes([
'path' => '<front>',
'url' => '',
'title' => '',
'class' => '',
'id' => '',
'style' => '',
'media_file_url' => FALSE,
], $attributes);
$url = $attributes['url'];
if (empty($url)) {
$url = $this
->getUrlFromPath($attributes['path'], $attributes['media_file_url']);
}
if ($text) {
$title = $this
->getTitleFromAttributes($attributes['title'], $text);
// Build element attributes to be used in twig.
$element_attributes = [
'href' => $url,
'class' => $attributes['class'],
'id' => $attributes['id'],
'style' => $attributes['style'],
'title' => $title,
];
// Filter away empty attributes.
$element_attributes = array_filter($element_attributes);
$output = [
'#theme' => 'shortcode_link',
// Not required for rendering, just for extra context.
'#url' => $url,
'#attributes' => $element_attributes,
'#text' => $text,
];
return $this
->render($output);
}
return $url;
}
/**
* {@inheritdoc}
*/
public function tips($long = FALSE) {
$output = [];
$output[] = '<p><strong>' . $this
->t('[link path="the drupal path" (title="link title"|class="additional class"|id="item id"|style="css style rules")]text[/link]') . '</strong>';
if ($long) {
$output[] = $this
->t('Inserts an aliased drupal path around the text. You can omit the text and the closing [/link], you get back the url only.') . '</p>';
$output[] = '<p>' . $this
->t('Additional class names can be added by the <em>class</em> parameter. The id parameter gives the html an unique css id. In the <em>style</em> parameter you can use your own css definition.') . '</p>';
}
else {
$output[] = $this
->t('Inserts an aliased drupal path around the text. You can omit the text and the closing [/link], you get back the url only.') . '</p>';
}
return implode(' ', $output);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
LinkShortcode:: |
public | function |
Performs the shortcode processing. Overrides ShortcodeInterface:: |
|
LinkShortcode:: |
public | function |
Generates a filter's tip. Overrides ShortcodeBase:: |
|
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:: |
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. | |
ShortcodeBase:: |
protected | property |
The plugin ID of this filter. Overrides PluginBase:: |
|
ShortcodeBase:: |
public | property | The name of the provider that owns this filter. | |
ShortcodeBase:: |
public | property | An associative array containing the configured settings of this filter. | |
ShortcodeBase:: |
public | property | A Boolean indicating whether this filter is enabled. | |
ShortcodeBase:: |
public | function | Add a class into a classes string if not already inside. | |
ShortcodeBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
|
ShortcodeBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
1 |
ShortcodeBase:: |
public | function |
Gets default configuration for this plugin. Overrides ConfigurableInterface:: |
|
ShortcodeBase:: |
public | function | Combines user attributes with known attributes. | |
ShortcodeBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
ShortcodeBase:: |
public | function |
Returns the administrative description for this shortcode plugin. Overrides ShortcodeInterface:: |
|
ShortcodeBase:: |
public | function | Returns image properties for a given image media entity id. | |
ShortcodeBase:: |
public | function |
Returns the administrative label for this shortcode plugin. Overrides ShortcodeInterface:: |
|
ShortcodeBase:: |
public | function | Get a media entity field. | |
ShortcodeBase:: |
public | function | Get the file url for a media object. | |
ShortcodeBase:: |
public | function | Extracts the media id from a 'media/x' system path. | |
ShortcodeBase:: |
public | function | Returns a suitable title string given the user provided title and text. | |
ShortcodeBase:: |
public | function | ||
ShortcodeBase:: |
public | function | Returns a url to be used in a link element given path or url. | |
ShortcodeBase:: |
public | function | Wrapper for renderPlain. | |
ShortcodeBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
ShortcodeBase:: |
public | function |
Generates a shortcode's settings form. Overrides ShortcodeInterface:: |
|
ShortcodeBase:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |
1 |
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. |