public function ExpandCollapseFormatter::settingsForm in Expand collapse 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/ ExpandCollapseFormatter.php, line 45 - Contains the ExpandCollapseFormatter class.
Class
- ExpandCollapseFormatter
- The expand collapse formatter.
Namespace
Drupal\expand_collapse_formatter\Plugin\Field\FieldFormatterCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$element = [];
$element['trim_length'] = [
'#title' => t('Trim length'),
'#type' => 'number',
'#default_value' => $this
->getSetting('trim_length'),
'#min' => 1,
'#required' => TRUE,
];
$element['default_state'] = [
'#title' => t('Default state'),
'#type' => 'select',
'#options' => [
'collapsed' => t('Collapsed'),
'expanded' => t('Expanded'),
],
'#default_value' => $this
->getSetting('default_state'),
'#required' => TRUE,
];
$element['link_text_open'] = [
'#title' => t('Link text (open)'),
'#type' => 'textfield',
'#default_value' => $this
->getSetting('link_text_open'),
'#required' => FALSE,
];
$element['link_text_close'] = [
'#title' => t('Link text (close)'),
'#type' => 'textfield',
'#default_value' => $this
->getSetting('link_text_close'),
'#required' => FALSE,
];
$element['link_class_open'] = [
'#title' => t('Link class (open)'),
'#type' => 'textfield',
'#default_value' => $this
->getSetting('link_class_open'),
'#required' => FALSE,
];
$element['link_class_close'] = [
'#title' => t('Link class (close)'),
'#type' => 'textfield',
'#default_value' => $this
->getSetting('link_class_close'),
'#required' => FALSE,
];
return $element;
}