public function DateRangeDurationWidget::settingsForm in Datetime Extras 8
Returns a form to configure settings for the widget.
Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the widget. 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 definition for the widget settings.
Overrides WidgetBase::settingsForm
File
- src/
Plugin/ Field/ FieldWidget/ DateRangeDurationWidget.php, line 117
Class
- DateRangeDurationWidget
- Plugin implementation of the 'daterange_duration' widget.
Namespace
Drupal\datetime_extras\Plugin\Field\FieldWidgetCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$element = [];
$element['duration_granularity'] = [
'#type' => 'granularity',
'#title' => t('Duration granularity'),
'#default_value' => $this
->getSetting('duration_granularity'),
];
$element['default_duration'] = [
'#type' => 'duration',
'#title' => t('Default duration'),
'#default_value' => $this
->getDefaultDurationInterval(),
'#granularity' => $this
->getSetting('duration_granularity'),
'#cardinality' => $this->fieldDefinition
->getFieldStorageDefinition()
->getCardinality(),
// Blast the default #element_validate callback to leave this duration
// as an array (and don't convert it into a DateInterval object), so we
// can save it to config storage.
// @see https://www.drupal.org/project/duration_field/issues/3020681
'#element_validate' => [],
];
$element['time_increment'] = [
'#type' => 'select',
'#title' => $this
->t('Time increment'),
'#default_value' => $this
->getSetting('time_increment'),
'#options' => $this
->getTimeIncrementOptions(),
];
return $element;
}