public function PhpMarkdownExtra::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 PhpMarkdown::buildConfigurationForm
File
- src/
Plugin/ Markdown/ PhpMarkdown/ PhpMarkdownExtra.php, line 106
Class
- PhpMarkdownExtra
- Support for PHP Markdown Extra by Michel Fortin.
Namespace
Drupal\markdown\Plugin\Markdown\PhpMarkdownCode
public function buildConfigurationForm(array $element, FormStateInterface $form_state) {
/** @var \Drupal\markdown\Form\SubformStateInterface $form_state */
$element = parent::buildConfigurationForm($element, $form_state);
$element += $this
->createSettingElement('code_attr_on_pre', [
'#type' => 'checkbox',
'#title' => $this
->t('Code Attribute on <code><pre></code>'),
'#description' => $this
->t('When enabled, attributes for code blocks will go on the <code><pre></code> tag; otherwise they will be placed on the <code><code></code> tag.'),
], $form_state);
$element += $this
->createSettingElement('code_class_prefix', [
'#type' => 'textfield',
'#title' => $this
->t('Code Class Prefix'),
'#description' => $this
->t('An optional prefix for the class names associated with fenced code blocks.'),
], $form_state);
$element += $this
->createSettingElement('hashtag_protection', [
'#type' => 'checkbox',
'#title' => $this
->t('Hashtag Protection'),
'#description' => $this
->t('When enabled, prevents ATX-style headers with no space after the initial hash from being interpreted as headers.'),
], $form_state);
$element += $this
->createSettingElement('table_align_class_tmpl', [
'#type' => 'textfield',
'#title' => $this
->t('Table Align Class Template'),
'#description' => $this
->t('The class attribute determining the alignment of table cells. The default value, which is empty, will cause the align attribute to be used instead of class to specify the alignment.<br>If not empty, the align attribute will not appear. Instead, the value for the class attribute will be determined by replacing any occurrence of <code>%%</code> within the string by left, center, or right. For instance, if set to <code>go-%%</code> and the cell is right-aligned, the result will be: <code>class="go-right"</code>.'),
], $form_state);
// Footnotes.
$footnote_variable = $this
->t('Occurrences of <code>^^</code> in the string will be replaced by the corresponding footnote number in the HTML output. Occurrences of <code>%%</code> will be replaced by a number for the reference (footnotes can have multiple references).');
$element['footnotes'] = [
'#weight' => 9,
'#type' => 'details',
'#open' => TRUE,
'#title' => $this
->t('Footnotes'),
'#parents' => $form_state
->createParents(),
];
$element['footnotes'] += $this
->createSettingElement('fn_backlink_class', [
'#type' => 'textfield',
'#title' => $this
->t('Backlink Class'),
'#description' => $this
->t('The <code>class</code> attribute to use for footnotes backlinks.<br>@var', [
'@var' => $footnote_variable,
]),
], $form_state);
$element['footnotes'] += $this
->createSettingElement('fn_backlink_html', [
'#type' => 'textfield',
'#title' => $this
->t('Backlink HTML'),
'#description' => $this
->t('HTML content for a footnote backlink. The <code>&#xFE0E;</code> suffix in the default value is there to avoid the curled arrow being rendered as an emoji on mobile devices, but it might cause an unrecognized character to appear on older browsers.<br>@var', [
'@var' => $footnote_variable,
]),
], $form_state);
$element['footnotes'] += $this
->createSettingElement('fn_backlink_label', [
'#type' => 'textfield',
'#title' => $this
->t('Backlink Label'),
'#description' => $this
->t('Add an accessibility label for backlinks (the <code>aria-label</code> attribute), when you want it to be different from the title attribute.<br>@var', [
'@var' => $footnote_variable,
]),
], $form_state);
$element['footnotes'] += $this
->createSettingElement('fn_backlink_title', [
'#type' => 'textfield',
'#title' => $this
->t('Backlink Title'),
'#description' => $this
->t('An optional <code>title</code> attribute for footnotes links and backlinks. Browsers usually show this as a tooltip when the mouse is over the link.<br>@var', [
'@var' => $footnote_variable,
]),
], $form_state);
$element['footnotes'] += $this
->createSettingElement('fn_id_prefix', [
'#type' => 'textfield',
'#title' => $this
->t('ID Prefix'),
'#description' => $this
->t('A prefix for the <code>id</code> attributes generated by footnotes. This is useful if you have multiple markdown documents displayed inside one HTML document to avoid footnote ids to clash each other.'),
], $form_state);
$element['footnotes'] += $this
->createSettingElement('fn_link_class', [
'#type' => 'textfield',
'#title' => $this
->t('Link Class'),
'#description' => $this
->t('The class attribute to use for footnotes links.<br>@var', [
'@var' => $footnote_variable,
]),
], $form_state);
$element['footnotes'] += $this
->createSettingElement('fn_link_title', [
'#type' => 'textfield',
'#title' => $this
->t('Link Title'),
'#description' => $this
->t('An optional <code>title</code> attribute for footnotes links. Browsers usually show this as a tooltip when the mouse is over the link.<br>@var', [
'@var' => $footnote_variable,
]),
], $form_state);
$element['footnotes'] += $this
->createSettingElement('omit_footnotes', [
'#type' => 'checkbox',
'#title' => $this
->t('Omit Footnotes'),
'#description' => $this
->t('When enabled, footnotes are not appended at the end of the generated HTML and the <code>footnotes_assembled</code> variable on the parser object (see <code>hook_markdown_html_alter()</code>) will contain the HTML for the footnote list, allowing footnotes to be moved somewhere else on the page.<br>NOTE: when placing the content of footnotes_assembled on the page, consider adding the attribute <code>role="doc-endnotes"</code> to the HTML element that will enclose the list of footnotes so they are reachable to accessibility tools the same way they would be with the default HTML output.'),
], $form_state);
// Predefined.
$element['predefined'] += $this
->createSettingElement('predef_abbr', [
'#weight' => -1,
'#type' => 'textarea',
'#title' => $this
->t('Abbreviations'),
'#description' => $this
->t('A predefined key|value pipe list of abbreviations, where the key is the value left of a pipe (<code>|</code>) and the abbreviation is to the right of it; only one key|value pipe item per line.<br>For example, adding the following <code>html|Hyper Text Markup Language</code> allows the following in markdown <code>*[html]</code> to be parsed and replaced with <code><abbr title="Hyper Text Markup Language">HTML</abbr></code>.'),
], $form_state, '\\Drupal\\markdown\\Util\\KeyValuePipeConverter::denormalize');
return $element;
}