You are here

public function PhpMarkdown::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

1 call to PhpMarkdown::buildConfigurationForm()
PhpMarkdownExtra::buildConfigurationForm in src/Plugin/Markdown/PhpMarkdown/PhpMarkdownExtra.php
Form constructor.
1 method overrides PhpMarkdown::buildConfigurationForm()
PhpMarkdownExtra::buildConfigurationForm in src/Plugin/Markdown/PhpMarkdown/PhpMarkdownExtra.php
Form constructor.

File

src/Plugin/Markdown/PhpMarkdown/PhpMarkdown.php, line 79

Class

PhpMarkdown
Support for PHP Markdown by Michel Fortin.

Namespace

Drupal\markdown\Plugin\Markdown\PhpMarkdown

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('enhanced_ordered_list', [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enhanced Ordered List'),
    '#description' => $this
      ->t('Enabling this allows ordered list to start with a number different from 1.'),
  ], $form_state);
  $element += $this
    ->createSettingElement('hard_wrap', [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Hard Wrap'),
    '#description' => $this
      ->t('Enabling this will change line breaks into <code>&lt;br /&gt;</code> when the context allows it. When disabled, following the standard Markdown syntax these newlines are ignored unless they a preceded by two spaces.'),
  ], $form_state);
  $element += $this
    ->createSettingElement('no_entities', [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('No Entities'),
    '#description' => $this
      ->t('Enabling this will prevent HTML entities (such as <code>&lt;</code>) from being passed verbatim in the output as it is the standard with Markdown. Instead, the HTML output will be <code>&amp;tl;</code> and once shown in shown the browser it will match perfectly what was written.'),
  ], $form_state);
  $this
    ->renderStrategyDisabledSettingState($form_state, $element['no_entities']);
  $element += $this
    ->createSettingElement('no_markup', [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('No Markup'),
    '#description' => $this
      ->t('Enabling this will prevent HTML tags from the input from being passed to the output.'),
  ], $form_state);
  $this
    ->renderStrategyDisabledSettingState($form_state, $element['no_markup']);
  $element += $this
    ->createSettingElement('empty_element_suffix', [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Empty Element Suffix'),
    '#description' => $this
      ->t('This is the string used to close tags for HTML elements with no content such as <code>&lt;br&gt;</code> and <code>&lt;hr&gt;</code>. The default value creates XML-style empty element tags which are also valid in HTML 5.'),
  ], $form_state);
  $element += $this
    ->createSettingElement('tab_width', [
    '#type' => 'number',
    '#title' => $this
      ->t('Tab Width'),
    '#description' => $this
      ->t('The width of a tab character on input. Changing this will affect how many spaces a tab character represents.<br>NOTE: Keep in mind that when the Markdown syntax spec says "four spaces or one tab", it actually means "four spaces after tabs are expanded to spaces". So this to <code>8</code> will make the parser treat a tab character as two levels of indentation.'),
    '#min' => 4,
    '#max' => 32,
  ], $form_state);
  $element['predefined'] = [
    '#weight' => 10,
    '#type' => 'details',
    '#open' => TRUE,
    '#title' => $this
      ->t('Predefined'),
    '#parents' => $form_state
      ->createParents(),
  ];
  $element['predefined'] += $this
    ->createSettingElement('predef_urls', [
    '#type' => 'textarea',
    '#title' => $this
      ->t('URLs'),
    '#description' => $this
      ->t('A predefined key|value pipe list of URLs, where the key is the value left of a pipe (<code>|</code>) and the URL is to the right of it; only one key|value pipe item per line.<br>For example, adding the following <code>example|http://www.example.com</code> allows the following in markdown <code>[click here][example]</code> to be parsed and replaced with <code>&lt;a href="http://www.example.com"&gt;click here&lt;/a&gt;</code>.'),
  ], $form_state, '\\Drupal\\markdown\\Util\\KeyValuePipeConverter::denormalize');
  $element['predefined'] += $this
    ->createSettingElement('predef_titles', [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Titles'),
    '#description' => $this
      ->t('A predefined key|value pipe list of titles, where the key is the value left of a pipe (<code>|</code>) and the URL is to the right of it; only one key|value pipe item per line.<br>The key must match a corresponding key in Predefined URLs and the value will be used to set the link title attribute.'),
  ], $form_state, '\\Drupal\\markdown\\Util\\KeyValuePipeConverter::denormalize');
  $form_state
    ->addElementState($element['predefined']['predef_titles'], 'disabled', 'predef_urls', [
    'value' => '',
  ]);
  return $element;
}