trait MoreInfoTrait in Markdown 8.2
Trait for appending content with "[More Info]" links.
@todo Move upstream to https://www.drupal.org/project/installable_plugins.
Hierarchy
- trait \Drupal\markdown\Traits\MoreInfoTrait uses RendererTrait
3 files declare their use of MoreInfoTrait
- FilterMarkdown.php in src/
Plugin/ Filter/ FilterMarkdown.php - InstallablePluginBase.php in src/
Plugin/ Markdown/ InstallablePluginBase.php - ParserConfigurationForm.php in src/
Form/ ParserConfigurationForm.php
File
- src/
Traits/ MoreInfoTrait.php, line 15
Namespace
Drupal\markdown\TraitsView source
trait MoreInfoTrait {
use RendererTrait;
/**
* Appends existing content with a "More Info" link.
*
* @param mixed $existing
* The existing content to append to.
* @param string|\Drupal\Core\Url $url
* The URL to use.
* @param string $label
* Optional. The "More Info" label to use for the link.
*
* @return \Drupal\Component\Render\MarkupInterface
* The new joined content.
*/
protected function moreInfo($existing, $url, $label = 'More Info') {
if (!$url) {
return $existing;
}
if (!$url instanceof Url) {
$url = UrlHelper::isExternal($url) ? Url::fromUri($url)
->setOption('attributes', [
'target' => '_blank',
]) : Url::fromUserInput($url);
}
if (!$label instanceof MarkupInterface) {
$label = $this
->t($label);
// phpcs:ignore
}
$build = [
'#type' => 'link',
'#title' => new FormattableMarkup('[@label]', [
'@label' => $label,
]),
'#url' => $url,
'#options' => [
'attributes' => [
'class' => [
'installable-more-info',
],
'title' => $label,
],
],
'#prefix' => ' ',
];
$moreInfo = $this
->renderer()
->renderPlain($build);
if (empty($existing) || empty(trim($existing))) {
return $moreInfo;
}
return new FormattableMarkup('@existing @moreInfo', [
'@existing' => $existing,
'@moreInfo' => $moreInfo,
]);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MoreInfoTrait:: |
protected | function | Appends existing content with a "More Info" link. | |
RendererTrait:: |
protected static | property | The Renderer service. | |
RendererTrait:: |
protected | function | Retrieves the Renderer service. |