You are here

public function AtAutolinker::alterGuidelines in Markdown 3.0.x

Alters existing guides on how to use the Markdown Parser.

Parameters

array $guides: The guides array, passed by reference.

Overrides MarkdownGuidelinesAlterInterface::alterGuidelines

File

src/Plugin/Markdown/Extension/AtAutolinker.php, line 27

Class

AtAutolinker
Plugin annotation @MarkdownExtension( id = "at_autolinker", label = @Translation("@ Autolinker"), installed = TRUE, description = @Translation("Automatically link commonly used references that come after an at character (@) without having to…

Namespace

Drupal\markdown\Plugin\Markdown\Extension

Code

public function alterGuidelines(array &$guides = []) {
  $user = \Drupal::currentUser();
  if ($user
    ->isAnonymous()) {
    $user = User::load(1);
  }
  if ($this
    ->getSetting('type') === 'user') {
    $description = [
      $this
        ->t('Text that starts with an at symbol (@) followed by any character other than a space will be automatically linked to users on this site.'),
    ];
    if ($this
      ->getSetting('format_username')) {
      $description[] = $this
        ->t('The formatted user name will be used in place of the text.');
    }
    $description[] = $this
      ->t('If the user does not exist, it will not automatically link.');
    $guides['links']['items'][] = [
      'title' => $this
        ->t('@ Autolinker'),
      'description' => $description,
      'tags' => [
        'a' => '@' . $user
          ->getAccountName(),
      ],
    ];
  }
  elseif ($this
    ->getSetting('type') === 'url') {
    $guides['links']['items'][] = [
      'title' => $this
        ->t('@ Autolinker'),
      'description' => $this
        ->t('Text that starts with an at symbol (@) followed by any character other than a space will automatically be linked to the following URL: <code>@url</code>', [
        '@url' => $this
          ->getSetting('url'),
      ]),
      'tags' => [
        'a' => [
          '@dries',
        ],
      ],
    ];
  }
}