public function LinkRenderer::settingsForm in Markdown 3.0.x
Returns the configuration form elements specific to this plugin.
Parameters
array $element: The element render array for the extension configuration form.
\Drupal\Core\Form\FormStateInterface $formState: The current state of the form.
\Drupal\markdown\Plugin\Filter\MarkdownFilterInterface $filter: The filter this form belongs to.
Return value
array The renderable form array representing the entire configuration form.
Overrides BaseExtension::settingsForm
File
- src/
Plugin/ Markdown/ Extension/ LinkRenderer.php, line 190
Class
- LinkRenderer
- Plugin annotation @MarkdownExtension( id = "enhanced_links", label = @Translation("Enhanced Links"), installed = TRUE, description = @Translation("Extends CommonMark to provide additional enhancements when rendering links."), parsers =…
Namespace
Drupal\markdown\Plugin\Markdown\ExtensionCode
public function settingsForm(array $element, FormStateInterface $formState, MarkdownFilterInterface $filter) {
$element = parent::settingsForm($element, $formState, $filter);
if (!empty($element['#description'])) {
$element['#description'] = '<p>' . $element['#description'] . '</p>';
}
elseif (!isset($element['#description'])) {
$element['#description'] = '';
}
$element['#description'] .= '<p><strong>' . $this
->t('NOTE: These settings ONLY apply to CommonMark Markdown links, if a user manually enters an <code><a></code> tag, then these settings will not be processed on them.') . '</strong></p>';
$element['internal_host_whitelist'] = [
'#type' => 'textarea',
'#title' => $this
->t('Internal Host Whitelist'),
'#description' => $this
->t('Allows additional host names to be treated as "internal" when they would normally be considered as "external". This is useful in cases where a multi-site is using different sub-domains. The current host name, %host, will always be considered "internal" (even if removed from this list). Enter one host name per line. No regular expressions are allowed, just exact host name matches.', [
'%host' => \Drupal::request()
->getHost(),
]),
'#default_value' => $this
->getSetting('internal_host_whitelist'),
];
$element['external_new_window'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Open external links in new windows'),
'#description' => $this
->t('When this setting is enabled, any link that does not contain one of the above internal whitelisted host names will automatically be considered as an "external" link. All external links will then have the <code>target="_blank"</code> attribute and value added to it.'),
'#default_value' => $this
->getSetting('external_new_window'),
];
$element['no_follow'] = [
'#type' => 'select',
'#title' => $this
->t('Add <code>rel="nofollow"</code> to'),
'#description' => $this
->t('The rel="nofollow" attribute and value instructs some search engines that the link should not influence the ranking of the link\'s target in the search engine\'s index.'),
'#default_value' => $this
->getSetting('no_follow'),
'#options' => [
'' => $this
->t('None of the links'),
'all' => $this
->t('All of the links'),
'external' => $this
->t('External links only'),
'internal' => $this
->t('Internal links only'),
],
];
return $element;
}