public function DurationHumanDisplayFormatter::settingsForm in Duration Field 8
Same name and namespace in other branches
- 8.2 src/Plugin/Field/FieldFormatter/DurationHumanDisplayFormatter.php \Drupal\duration_field\Plugin\Field\FieldFormatter\DurationHumanDisplayFormatter::settingsForm()
- 3.0.x src/Plugin/Field/FieldFormatter/DurationHumanDisplayFormatter.php \Drupal\duration_field\Plugin\Field\FieldFormatter\DurationHumanDisplayFormatter::settingsForm()
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/ DurationHumanDisplayFormatter.php, line 117
Class
- DurationHumanDisplayFormatter
- Provides a formatter for the duration field type.
Namespace
Drupal\duration_field\Plugin\Field\FieldFormatterCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$element['text_length'] = [
'#title' => t('Text length'),
'#type' => 'select',
'#options' => [
'full' => $this
->getHumanFriendlyLabel('full'),
'short' => $this
->getHumanFriendlyLabel('short'),
],
'#default_value' => $this
->getSetting('text_length'),
];
$custom_separators = $this->moduleHandler
->invokeAll('duration_field_separators');
$custom_separator_mappings = [];
foreach (array_keys($custom_separators) as $custom_separator) {
$custom_separator_mappings[$custom_separator] = $this
->getHumanFriendlyLabel($custom_separator);
}
$element['separator'] = [
'#title' => $this
->t('Separator'),
'#type' => 'select',
'#options' => [
'space' => $this
->getHumanFriendlyLabel('space'),
'hyphen' => $this
->getHumanFriendlyLabel('hyphen'),
'comma' => $this
->getHumanFriendlyLabel('comma'),
'newline' => $this
->getHumanFriendlyLabel('newline'),
] + $custom_separator_mappings,
'#default_value' => $this
->getSetting('separator'),
];
return $element;
}