public function SpamspanSettingsFormTrait::settingsForm in SpamSpan filter 8
Same name and namespace in other branches
- 8.2 src/SpamspanSettingsFormTrait.php \Drupal\spamspan\SpamspanSettingsFormTrait::settingsForm()
File
- src/
SpamspanSettingsFormTrait.php, line 15
Class
- SpamspanSettingsFormTrait
- Provides a common Settings form for Spamspan plugins.
Namespace
Drupal\spamspanCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$element = [];
// Spamspan '@' replacement.
$element['spamspan_at'] = [
'#type' => 'textfield',
'#title' => $this
->t('Replacement for "@"'),
'#default_value' => $this
->getSetting('spamspan_at'),
'#required' => TRUE,
'#description' => $this
->t('Replace "@" with this text when javascript is disabled.'),
];
$element['spamspan_use_graphic'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Use a graphical replacement for "@"'),
'#default_value' => $this
->getSetting('spamspan_use_graphic'),
'#description' => $this
->t('Replace "@" with a graphical representation when javascript is disabled (and ignore the setting "Replacement for @" above).'),
];
$element['spamspan_dot_enable'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Replace dots in email with text'),
'#default_value' => $this
->getSetting('spamspan_dot_enable'),
'#description' => $this
->t('Switch on dot replacement.'),
];
$element['spamspan_dot'] = [
'#type' => 'textfield',
'#title' => $this
->t('Replacement for "."'),
'#default_value' => $this
->getSetting('spamspan_dot'),
'#required' => TRUE,
'#description' => $this
->t('Replace "." with this text.'),
];
// No trees, see https://www.drupal.org/node/2378437.
// We fix this in our custom validate handler.
$element['use_form'] = [
'#type' => 'details',
'#title' => $this
->t('Use a form instead of a link'),
'#open' => TRUE,
];
$element['use_form']['spamspan_use_form'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Use a form instead of a link'),
'#default_value' => $this
->getSetting('spamspan_use_form'),
'#description' => $this
->t('Link to a contact form instead of an email address. The following settings are used only if you select this option.'),
];
$element['use_form']['spamspan_form_pattern'] = [
'#type' => 'textfield',
'#title' => $this
->t('Replacement string for the email address'),
'#default_value' => $this
->getSetting('spamspan_form_pattern'),
'#required' => TRUE,
'#description' => $this
->t('Replace the email link with this string and substitute the following: <br />%url = the url where the form resides,<br />%email = the email address (base64 and urlencoded),<br />%displaytext = text to display instead of the email address.'),
];
$element['use_form']['spamspan_form_default_url'] = [
'#type' => 'textfield',
'#title' => $this
->t('Default url'),
'#default_value' => $this
->getSetting('spamspan_form_default_url'),
'#required' => TRUE,
'#description' => $this
->t('Default url to form to use if none specified (e.g. me@example.com[custom_url_to_form])'),
];
$element['use_form']['spamspan_form_default_displaytext'] = [
'#type' => 'textfield',
'#title' => $this
->t('Default displaytext'),
'#default_value' => $this
->getSetting('spamspan_form_default_displaytext'),
'#required' => TRUE,
'#description' => $this
->t('Default displaytext to use if none specified (e.g. me@example.com[custom_url_to_form|custom_displaytext])'),
];
// We need this to insert our own validate/submit handlers.
// We use our own validate handler to extract use_form settings.
$element['#process'] = [
[
$this,
'processSettingsForm',
],
];
return $element;
}