You are here

public function ExternalLinkExtension::buildConfigurationForm in Markdown 8.2

Form constructor.

Plugin forms are embedded in other forms. In order to know where the plugin form is located in the parent form, #parents and #array_parents must be known, but these are not available during the initial build phase. In order to have these properties available when building the plugin form's elements, let this method return a form element that has a #process callback and build the rest of the form in the callback. By the time the callback is executed, the element's #parents and #array_parents properties will have been set by the form API. For more documentation on #parents and #array_parents, see \Drupal\Core\Render\Element\FormElement.

Parameters

array $form: An associative array containing the initial structure of the plugin form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

Return value

array The form structure.

Overrides PluginFormInterface::buildConfigurationForm

File

src/Plugin/Markdown/CommonMark/Extension/ExternalLinkExtension.php, line 103

Class

ExternalLinkExtension
Plugin annotation @MarkdownAllowedHtml( id = "commonmark-external-links", ) @MarkdownExtension( id = "commonmark-external-links", label = @Translation("External Links"), description = @Translation("Automatically detect links to external sites…

Namespace

Drupal\markdown\Plugin\Markdown\CommonMark\Extension

Code

public function buildConfigurationForm(array $element, FormStateInterface $form_state) {

  /** @var \Drupal\markdown\Form\SubformStateInterface $form_state */
  $element += $this
    ->createSettingElement('internal_hosts', [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Internal Hosts'),
    '#description' => $this
      ->t('Defines a whitelist of hosts which are considered non-external and should not receive the external link treatment. This can be a single host name, like <code>example.com</code>, which must match exactly. Wildcard matching is also supported using regular expression like <code>/(^|\\.)example\\.com$/</code>. Note that you must use <code>/</code> characters to delimit your regex. By default, if no internal hosts are provided, all links will be considered external. One host per line.'),
  ], $form_state, '\\Drupal\\markdown\\Util\\KeyValuePipeConverter::denormalizeNoKeys');
  $element['token'] = FormTrait::createTokenBrowser();
  $element += $this
    ->createSettingElement('html_class', [
    '#type' => 'textfield',
    '#title' => $this
      ->t('HTML Class'),
    '#description' => $this
      ->t('An HTML class that should be added to external link <code>&lt;a&gt;</code> tags.'),
  ], $form_state);
  $element += $this
    ->createSettingElement('open_in_new_window', [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Open in a New Window'),
    '#description' => $this
      ->t('Adds <code>target="_blank"</code> to external link <code>&lt;a&gt;</code> tags.'),
  ], $form_state);
  $relOptions = [
    '' => $this
      ->t('No links'),
    'all' => $this
      ->t('All links'),
    'external' => $this
      ->t('External links only'),
    'internal' => $this
      ->t('Internal links only'),
  ];
  $element += $this
    ->createSettingElement('nofollow', [
    '#type' => 'select',
    '#title' => $this
      ->t('No Follow'),
    '#description' => $this
      ->t('Sets the "nofollow" value in the <code>rel</code> attribute. This value instructs search engines to not influence the ranking of the link\'s target in the search engine\'s index. Using this can negatively impact your site\'s SEO ranking if done improperly.'),
    '#options' => $relOptions,
  ], $form_state);
  $element += $this
    ->createSettingElement('noopener', [
    '#type' => 'select',
    '#title' => $this
      ->t('No Opener'),
    '#description' => $this
      ->t('Sets the "noopener" value in the <code>rel</code> attribute. This value instructs the browser to prevent the new page from being able to access the the window that opened the link and forces it run in a separate process.'),
    '#options' => $relOptions,
  ], $form_state);
  $element += $this
    ->createSettingElement('noreferrer', [
    '#type' => 'select',
    '#title' => $this
      ->t('No Referrer'),
    '#description' => $this
      ->t('Sets the "noreferrer" value in the <code>rel</code> attribute. This value instructs the browser from sending an HTTP referrer header to ensure that no referrer information will be leaked.'),
    '#options' => $relOptions,
  ], $form_state);
  return $element;
}