You are here

public function InstallablePluginTrait::getLink in Markdown 8.2

Retrieves the plugin as a link using its label and URL.

Parameters

string|\Drupal\Component\Render\MarkupInterface $label: Optional. A specific label to use for the link. If not specified, it will default to the label or plugin identifier if present.

array $options: An array of options to pass to the Url object constructor.

bool $fallback: Flag indicating whether to fallback to the original label or plugin identifier if no link could be generated.

Return value

\Drupal\Core\GeneratedLink|mixed|void The link if one was generated or the label if $fallback was provided.

1 call to InstallablePluginTrait::getLink()
InstallableLibrary::createObjectRequirement in src/Annotation/InstallableLibrary.php

File

src/Annotation/InstallablePluginTrait.php, line 159

Class

InstallablePluginTrait
Trait for adding installable plugin properties to annotations.

Namespace

Drupal\markdown\Annotation

Code

public function getLink($label = NULL, array $options = [], $fallback = TRUE) {
  if (!isset($label)) {
    $label = $this->label ?: $this->id;
  }
  if ($url = $this
    ->getUrl($options)) {
    return Link::fromTextAndUrl($label, $url)
      ->toString();
  }
  elseif ($fallback) {
    return $label;
  }
}