You are here

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

Class

HeadingPermalinkExtension
Plugin annotation @MarkdownAllowedHtml( id = "commonmark-heading-permalink", ) @MarkdownExtension( id = "commonmark-heading-permalink", label = @Translation("Heading Permalink"), description = @Translation("Makes all heading elements…

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('html_class', [
    '#type' => 'textfield',
    '#title' => $this
      ->t('HTML Class'),
    '#description' => $this
      ->t("The value of this nested configuration option should be a <code>string</code> that you want set as the <code>&lt;a&gt;</code> tag's class attribute."),
  ], $form_state);
  $element += $this
    ->createSettingElement('id_prefix', [
    '#type' => 'textfield',
    '#title' => $this
      ->t('ID Prefix'),
    '#description' => $this
      ->t("This should be a <code>string</code> you want prepended to HTML IDs. This prevents generating HTML ID attributes which might conflict with others in your stylesheet. A dash separator (-) will be added between the prefix and the ID. You can instead set this to an empty string ('') if you don’t want a prefix."),
  ], $form_state);
  $element += $this
    ->createSettingElement('inner_contents', [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Inner Contents'),
    '#description' => $this
      ->t("This controls the HTML you want to appear inside of the generated <code>&lt;a&gt;</code> tag. Usually this would be something you'd style as some kind of link icon. By default, an embedded <a href=\":octicon-link\" target=\"_blank\">Octicon link SVG,</a> is provided, but you can replace this with any custom HTML you wish.<br>NOTE: The HTML tags and attributes saved here will be dynamically allowed using the corresponding Allowed HTML Plugin in \"Render Strategy\". This means that whatever is added here has the potential to open up security vulnerabilities.<br>If unsure or you wish for maximum security, use a non-HTML based placeholder (e.g. <code>{{ commonmark_heading_permalink_inner_contents }}</code>) value that you can replace post parsing in <code>hook_markdown_html_alter()</code>.", [
      ':octicon-link' => 'https://primer.style/octicons/link',
    ]),
  ], $form_state);
  $element += $this
    ->createSettingElement('insert', [
    '#type' => 'select',
    '#title' => $this
      ->t('Insert'),
    '#description' => $this
      ->t("This controls whether the anchor is added to the beginning of the <code>&lt;h1&gt;</code>, <code>&lt;h2&gt;</code> etc. tag or to the end."),
    '#options' => [
      'after' => $this
        ->t('After'),
      'before' => $this
        ->t('Before'),
    ],
  ], $form_state);
  $element += $this
    ->createSettingElement('title', [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Title'),
    '#description' => $this
      ->t("This option sets the title attribute on the <code>&lt;a&gt;</code> tag."),
  ], $form_state);
  return $element;
}