You are here

protected function DatePopupTrait::applyDatePopupToForm in Date Popup 8

Apply the HTML5 date popup to the views filter form.

Parameters

array $form: The form to apply it to.

3 calls to DatePopupTrait::applyDatePopupToForm()
DatePopup::buildExposedForm in src/DatePopup.php
Render our chunk of the exposed filter form when selecting
DatePopupSearchApi::buildExposedForm in src/DatePopupSearchApi.php
Render our chunk of the exposed filter form when selecting
DatetimePopup::buildExposedForm in src/DatetimePopup.php
Render our chunk of the exposed filter form when selecting

File

src/DatePopupTrait.php, line 16

Class

DatePopupTrait
Shared code between the Date and Datetime plugins.

Namespace

Drupal\date_popup

Code

protected function applyDatePopupToForm(array &$form) {
  if (!empty($this->options['expose']['identifier'])) {
    $identifier = $this->options['expose']['identifier'];

    // Identify wrapper.
    $wrapper_key = $identifier . '_wrapper';
    if (isset($form[$wrapper_key])) {
      $element =& $form[$wrapper_key][$identifier];
    }
    else {
      $element =& $form[$identifier];
    }

    // Detect filters that are using min/max.
    if (isset($element['min'])) {
      $element['min']['#type'] = 'date';
      $element['max']['#type'] = 'date';
      if (isset($element['value'])) {
        $element['value']['#type'] = 'date';
      }
    }
    else {
      $element['#type'] = 'date';
    }
  }
}