public function WrapperClassFormatter::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/ WrapperClassFormatter.php, line 50
Class
- WrapperClassFormatter
- A field formatter for wrapping text with a class.
Namespace
Drupal\element_class_formatter\Plugin\Field\FieldFormatterCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$elements = parent::settingsForm($form, $form_state);
$class = $this
->getSetting('class');
$elements['link'] = [
'#title' => $this
->t('Link to the Content'),
'#type' => 'checkbox',
'#description' => $this
->t('Wrap the text with a link to the content.'),
'#default_value' => $this
->getSetting('link'),
];
$elements['link_class'] = [
'#title' => $this
->t('Link class'),
'#type' => 'textfield',
'#default_value' => $this
->getSetting('link_class'),
'#states' => [
'visible' => [
':input[name$="[link]"]' => [
'checked' => TRUE,
],
],
],
];
$wrapper_options = [
'span' => 'span',
'div' => 'div',
'p' => 'p',
'strong' => 'strong',
];
foreach (range(1, 5) as $level) {
$wrapper_options['h' . $level] = 'H' . $level;
}
$elements['tag'] = [
'#title' => $this
->t('Tag'),
'#type' => 'select',
'#description' => $this
->t('Select the tag which will be wrapped around the text.'),
'#options' => $wrapper_options,
'#default_value' => $this
->getSetting('tag'),
];
$elements['summary'] = [
'#title' => $this
->t('Use summary'),
'#type' => 'checkbox',
'#description' => $this
->t('Output the summary instead of the field value.'),
'#default_value' => $this
->getSetting('summary'),
'#access' => $this->fieldDefinition
->getType() === 'text_with_summary',
];
$elements['trim'] = [
'#title' => $this
->t('Trim'),
'#type' => 'number',
'#min' => 1,
'#description' => $this
->t('Trim length of value when summary is not set.'),
'#default_value' => $this
->getSetting('trim'),
'#access' => $this->fieldDefinition
->getType() === 'text_with_summary',
];
return $this
->elementClassSettingsForm($elements, $class);
}