You are here

public function HashAutolinker::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/HashAutolinker.php, line 180

Class

HashAutolinker
Plugin annotation @MarkdownExtension( id = "hash_autolinker", label = @Translation("# Autolinker"), installed = TRUE, description = @Translation("Automatically link commonly used references that come after a hash character (#) without having…

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' => [
      'node' => $this
        ->t('Node'),
      'url' => $this
        ->t('URL'),
    ],
  ];
  $element['node_title'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Replace text with title of node'),
    '#description' => $this
      ->t('If enabled, it will replace the matched text with the title of the node.'),
    '#default_value' => $this
      ->getSetting('node_title'),
    '#states' => [
      'visible' => [
        $selector => [
          'value' => 'node',
        ],
      ],
    ],
  ];
  $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>%23</code>. Example: <code>https://twitter.com/search?q=%23[text]</code>.'),
    '#default_value' => $this
      ->getSetting('url'),
    '#states' => [
      'visible' => [
        $selector => [
          'value' => 'url',
        ],
      ],
    ],
  ];
  $element['url_title'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Replace text with title of URL'),
    '#description' => $this
      ->t('If enabled, it will replace the matched text with the title of the URL.'),
    '#default_value' => $this
      ->getSetting('url_title'),
    '#states' => [
      'visible' => [
        $selector => [
          'value' => 'url',
        ],
      ],
    ],
  ];
  return $element;
}