function DateRangeWidgetBase::formElement

Same name in other branches
  1. 9 core/modules/datetime_range/src/Plugin/Field/FieldWidget/DateRangeWidgetBase.php \Drupal\datetime_range\Plugin\Field\FieldWidget\DateRangeWidgetBase::formElement()
  2. 8.9.x core/modules/datetime_range/src/Plugin/Field/FieldWidget/DateRangeWidgetBase.php \Drupal\datetime_range\Plugin\Field\FieldWidget\DateRangeWidgetBase::formElement()
  3. 11.x core/modules/datetime_range/src/Plugin/Field/FieldWidget/DateRangeWidgetBase.php \Drupal\datetime_range\Plugin\Field\FieldWidget\DateRangeWidgetBase::formElement()

Overrides DateTimeWidgetBase::formElement

2 calls to DateRangeWidgetBase::formElement()
DateRangeDatelistWidget::formElement in core/modules/datetime_range/src/Plugin/Field/FieldWidget/DateRangeDatelistWidget.php
Returns the form for a single field widget.
DateRangeDefaultWidget::formElement in core/modules/datetime_range/src/Plugin/Field/FieldWidget/DateRangeDefaultWidget.php
Returns the form for a single field widget.
2 methods override DateRangeWidgetBase::formElement()
DateRangeDatelistWidget::formElement in core/modules/datetime_range/src/Plugin/Field/FieldWidget/DateRangeDatelistWidget.php
Returns the form for a single field widget.
DateRangeDefaultWidget::formElement in core/modules/datetime_range/src/Plugin/Field/FieldWidget/DateRangeDefaultWidget.php
Returns the form for a single field widget.

File

core/modules/datetime_range/src/Plugin/Field/FieldWidget/DateRangeWidgetBase.php, line 20

Class

DateRangeWidgetBase
Base class for the 'daterange_*' widgets.

Namespace

Drupal\datetime_range\Plugin\Field\FieldWidget

Code

public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
    $element = parent::formElement($items, $delta, $element, $form, $form_state);
    // Wrap all of the select elements with a fieldset.
    $element['#theme_wrappers'][] = 'fieldset';
    $element['#element_validate'][] = [
        $this,
        'validateStartEnd',
    ];
    $element['value']['#title'] = $this->t('Start date');
    $element['end_value'] = [
        '#title' => $this->t('End date'),
    ] + $element['value'];
    if ($items[$delta]->start_date) {
        
        /** @var \Drupal\Core\Datetime\DrupalDateTime $start_date */
        $start_date = $items[$delta]->start_date;
        $element['value']['#default_value'] = $this->createDefaultValue($start_date, $element['value']['#date_timezone']);
    }
    if ($items[$delta]->end_date) {
        
        /** @var \Drupal\Core\Datetime\DrupalDateTime $end_date */
        $end_date = $items[$delta]->end_date;
        $element['end_value']['#default_value'] = $this->createDefaultValue($end_date, $element['end_value']['#date_timezone']);
    }
    return $element;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.