You are here

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

Class

Parsedown
Support for Parsedown by Emanuil Rusev.

Namespace

Drupal\markdown\Plugin\Markdown\Parsedown

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('breaks_enabled', [
    '#access' => !!$this
      ->getSettingMethod('breaks_enabled'),
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Automatic line breaks'),
    '#description' => $this
      ->t('Enabling this will use line breaks (<code>&lt;br&gt;</code>) when a new line is detected instead of creating separate paragraphs (<code>&lt;p&gt;</code>).'),
  ], $form_state);
  $element += $this
    ->createSettingElement('markup_escaped', [
    '#access' => !!$this
      ->getSettingMethod('markup_escaped'),
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Markup Escaped'),
    '#description' => $this
      ->t('Enabling this will escape HTML markup.'),
  ], $form_state);
  $this
    ->renderStrategyDisabledSettingState($form_state, $element['markup_escaped']);
  $element += $this
    ->createSettingElement('safe_mode', [
    '#access' => !!$this
      ->getSettingMethod('safe_mode'),
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Safe Mode'),
    '#description' => $this
      ->t('Enabling this will apply sanitization to additional scripting vectors (such as scripting link destinations) that are introduced by the markdown syntax itself.'),
  ], $form_state);
  $this
    ->renderStrategyDisabledSettingState($form_state, $element['safe_mode']);

  // Always disable safe_mode and markup_escaped when using a render strategy.
  if ($this
    ->getRenderStrategy() !== static::NONE) {
    $element['markup_escaped']['#value'] = FALSE;
    $element['safe_mode']['#value'] = FALSE;
  }
  $element += $this
    ->createSettingElement('strict_mode', [
    '#access' => !!$this
      ->getSettingMethod('strict_mode'),
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Strict Mode'),
    '#description' => $this
      ->t('Enables strict CommonMark compliance.'),
  ], $form_state);
  $element += $this
    ->createSettingElement('urls_linked', [
    '#access' => !!$this
      ->getSettingMethod('urls_linked'),
    '#type' => 'checkbox',
    '#title' => $this
      ->t('URLs linked'),
    '#description' => $this
      ->t('Enabling this will automatically create links for URLs.'),
  ], $form_state);
  return $element;
}