public function LinkAllyFormatter::settingsForm in Element Class Formatter 8
Returns a form to configure settings for the formatter.
Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the formatter. The field_ui module takes care of handling submitted form values.
Parameters
array $form: The form where the settings form is being included in.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form elements for the formatter settings.
Overrides FormatterBase::settingsForm
File
- src/
Plugin/ Field/ FieldFormatter/ LinkAllyFormatter.php, line 63
Class
- LinkAllyFormatter
- Defines a formatter that allows links with screenreader only text.
Namespace
Drupal\element_class_formatter\Plugin\Field\FieldFormatterCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$elements = parent::settingsForm($form, $form_state);
$elements['link_text'] = [
'#title' => $this
->t('Link text'),
'#type' => 'textfield',
'#default_value' => $this
->getSetting('link_text'),
'#description' => $this
->t('Custom link text - leave empty to use the field value.'),
];
$elements['screenreader_text'] = [
'#title' => $this
->t('Screenreader text'),
'#type' => 'textfield',
'#default_value' => $this
->getSetting('screenreader_text'),
'#description' => $this
->t('Screenreader text - tokens are available.'),
];
$class = $this
->getSetting('class');
$wrapper_options = [
'span' => 'span',
'div' => 'div',
'p' => 'p',
];
foreach (range(1, 5) as $level) {
$wrapper_options['h' . $level] = 'H' . $level;
}
$elements['tag'] = [
'#title' => $this
->t('Tag'),
'#type' => 'select',
'#description' => $this
->t('Select an optional tag that will be wrapped around the link.'),
'#options' => $wrapper_options,
'#default_value' => $this
->getSetting('tag'),
'#empty_value' => '',
'#empty_option' => $this
->t('None'),
];
return $this
->elementClassSettingsForm($elements, $class);
}