You are here

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

Class

FootnoteExtension
Footnotes extension.

Namespace

Drupal\markdown\Plugin\Markdown\CommonMark\Extension

Code

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

  /** @var \Drupal\markdown\Form\SubformStateInterface $form_state */

  // Add a note about core's aggressive XSS and how it affects footnotes.
  // @todo Remove note about core XSS bug/workaround.
  // @see https://www.drupal.org/project/markdown/issues/3136378
  if (!$this
    ->isPreferredLibraryInstalled()) {
    $parent =& $form_state
      ->getParentForm();
    $parent['xss_bug'] = static::createInlineMessage([
      'warning' => [
        $this
          ->t('There is a known bug that prevents footnote identifiers from being rendered properly due to aggressive XSS filtering. There is a <a href=":issue" target="_blank">temporary workaround</a>, but you must manually implement it in a custom module. It is highly recommended that you instead upgrade to a newer version of CommonMark (1.5+) which includes a new bundled Footnotes extension where these settings are customizable.', [
          ':issue' => 'https://www.drupal.org/project/markdown/issues/3131224#comment-13613381',
        ]),
      ],
    ]);
    return $element;
  }
  $element += $this
    ->createSettingElement('backref_class', [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Back Reference Class'),
    '#description' => $this
      ->t('Defines which HTML class should be assigned to rendered footnote back reference elements.'),
  ], $form_state);
  $element += $this
    ->createSettingElement('container_add_hr', [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Container Add Horizontal Rule'),
    '#description' => $this
      ->t('Controls whether an <code>&lt;hr&gt;</code> element should be added inside the container.  Disable this if you want more control over how the footnote section at the bottom is differentiated from the rest of the document.'),
  ], $form_state);
  $element += $this
    ->createSettingElement('container_class', [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Container Class'),
    '#description' => $this
      ->t('Defines which HTML class should be assigned to the container at the bottom of the page which shows all the footnotes.'),
  ], $form_state);
  $element += $this
    ->createSettingElement('footnote_class', [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Footnote Class'),
    '#description' => $this
      ->t('Defines which HTML class should be assigned to rendered footnote elements.'),
  ], $form_state);
  $element += $this
    ->createSettingElement('footnote_id_prefix', [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Footnote ID Prefix'),
    '#description' => $this
      ->moreInfo($this
      ->t('Defines the prefix prepended to footnote elements. Note: due to a core bug, the use of colons (:) is not possible.'), 'https://www.drupal.org/project/drupal/issues/2544110'),
  ], $form_state);
  $element += $this
    ->createSettingElement('ref_class', [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Reference Class'),
    '#description' => $this
      ->t('Defines which HTML class should be assigned to rendered footnote reference elements.'),
  ], $form_state);
  $element += $this
    ->createSettingElement('ref_id_prefix', [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Reference ID Prefix'),
    '#description' => $this
      ->moreInfo($this
      ->t('Defines the prefix prepended to footnote references. Note: due to a core bug, the use of colons (:) is not possible.'), 'https://www.drupal.org/project/drupal/issues/2544110'),
  ], $form_state);
  return $element;
}