You are here

public function AtAutolinker::settingsForm in Markdown 3.0.x

Returns the configuration form elements specific to this plugin.

Parameters

array $element: The element render array for the extension configuration form.

\Drupal\Core\Form\FormStateInterface $formState: The current state of the form.

\Drupal\markdown\Plugin\Filter\MarkdownFilterInterface $filter: The filter this form belongs to.

Return value

array The renderable form array representing the entire configuration form.

Overrides BaseExtension::settingsForm

File

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

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 settingsForm(array $element, FormStateInterface $formState, MarkdownFilterInterface $filter) {
  $element = parent::settingsForm($element, $formState, $filter);
  $selector = $this
    ->getSatesSelector($this
    ->getElementParents($element, [
    $this
      ->getPluginId(),
  ]), 'type');
  $element['type'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Map text to'),
    '#default_value' => $this
      ->getSetting('type'),
    '#options' => [
      'user' => $this
        ->t('User'),
      'url' => $this
        ->t('URL'),
    ],
  ];
  $element['format_username'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Replace username with formatted display name'),
    '#description' => $this
      ->t('If enabled, it will replace the matched text with the formatted username.'),
    '#default_value' => $this
      ->getSetting('format_username'),
    '#states' => [
      'visible' => [
        $selector => [
          'value' => 'user',
        ],
      ],
    ],
  ];
  $element['url'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('URL'),
    '#description' => $this
      ->t('A URL to format text with. Use the token "[text]" where it is needed. If you need to include the @, use the URL encoded equivalent: <code>%40</code>. Example: <code>https://twitter.com/search?q=%40[text]</code>.'),
    '#default_value' => $this
      ->getSetting('url'),
    '#states' => [
      'visible' => [
        $selector => [
          'value' => 'url',
        ],
      ],
    ],
  ];
  return $element;
}