You are here

public function CommonMark::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 BaseParser::buildConfigurationForm

File

src/Plugin/Markdown/CommonMark/CommonMark.php, line 190

Class

CommonMark
Support for CommonMark by The League of Extraordinary Packages.

Namespace

Drupal\markdown\Plugin\Markdown\CommonMark

Code

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

  /** @var \Drupal\markdown\Form\SubformStateInterface $form_state */
  $element = parent::buildConfigurationForm($element, $form_state);
  $element += $this
    ->createSettingElement('allow_unsafe_links', [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Allow Unsafe Links'),
    '#description' => $this
      ->t('Allows potentially risky links and image URLs to remain in the document.'),
  ], $form_state);
  $this
    ->renderStrategyDisabledSettingState($form_state, $element['allow_unsafe_links']);
  $element += $this
    ->createSettingElement('enable_em', [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable Emphasis'),
    '#description' => $this
      ->t('Enables <code>&lt;em&gt;</code> parsing.'),
  ], $form_state);
  $element += $this
    ->createSettingElement('enable_strong', [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable Strong'),
    '#description' => $this
      ->t('Enables <code>&lt;strong&gt;</code> parsing.'),
  ], $form_state);
  $element += $this
    ->createSettingElement('html_input', [
    '#weight' => -1,
    '#type' => 'select',
    '#title' => $this
      ->t('HTML Input'),
    '#description' => $this
      ->t('Strategy to use when handling raw HTML input.'),
    '#options' => [
      'allow' => $this
        ->t('Allow'),
      'escape' => $this
        ->t('Escape'),
      'strip' => $this
        ->t('Strip'),
    ],
  ], $form_state);
  $this
    ->renderStrategyDisabledSettingState($form_state, $element['html_input']);

  // Always allow html_input when using a render strategy.
  if ($this
    ->getRenderStrategy() !== static::NONE) {
    $element['html_input']['#value'] = 'allow';
  }
  $element += $this
    ->createSettingElement('max_nesting_level', [
    '#type' => 'number',
    '#title' => $this
      ->t('Maximum Nesting Level'),
    '#description' => $this
      ->t('The maximum nesting level for blocks. Setting this to a positive integer can help protect against long parse times and/or segfaults if blocks are too deeply-nested.'),
    '#min' => 0,
    '#max' => 100000,
  ], $form_state, 'intval');
  $element['renderer'] = [
    '#type' => 'container',
  ];
  $rendererSubformState = SubformState::createForSubform($element['renderer'], $element, $form_state);
  $element['renderer'] += $this
    ->createSettingElement('renderer.block_separator', [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Block Separator'),
    '#description' => $this
      ->t('String to use for separating renderer block elements.'),
  ], $rendererSubformState, '\\Drupal\\markdown\\Plugin\\Markdown\\CommonMark\\CommonMark::addcslashes');
  $element['renderer'] += $this
    ->createSettingElement('renderer.inner_separator', [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Inner Separator'),
    '#description' => $this
      ->t('String to use for separating inner block contents.'),
  ], $rendererSubformState, '\\Drupal\\markdown\\Plugin\\Markdown\\CommonMark\\CommonMark::addcslashes');
  $element['renderer'] += $this
    ->createSettingElement('renderer.soft_break', [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Soft Break'),
    '#description' => $this
      ->t('String to use for rendering soft breaks.'),
  ], $rendererSubformState, '\\Drupal\\markdown\\Plugin\\Markdown\\CommonMark\\CommonMark::addcslashes');
  $element['renderer']['#access'] = $element['renderer']['block_separator']['#access'];
  $element += $this
    ->createSettingElement('use_asterisk', [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Use Asterisk'),
    '#description' => $this
      ->t('Enables parsing of <code>*</code> for emphasis.'),
  ], $form_state);
  $element += $this
    ->createSettingElement('use_underscore', [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Use Underscore'),
    '#description' => $this
      ->t('Enables parsing of <code>_</code> for emphasis.'),
  ], $form_state);
  $element += $this
    ->createSettingElement('unordered_list_markers', [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Unordered List Markers'),
    '#description' => $this
      ->t('Characters that are used to indicated a bulleted list; only one character per line.'),
  ], $form_state, '\\Drupal\\markdown\\Util\\KeyValuePipeConverter::denormalizeNoKeys');
  return $element;
}