You are here

public function DateFilter::buildForm in Visitors 8.2

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides FormInterface::buildForm

1 call to DateFilter::buildForm()
Referers::buildForm in src/Form/Referers.php
Form constructor.
1 method overrides DateFilter::buildForm()
Referers::buildForm in src/Form/Referers.php
Form constructor.

File

src/Form/DateFilter.php, line 47

Class

DateFilter

Namespace

Drupal\visitors\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $this
    ->_setSessionDateRange();
  $from = DrupalDateTime::createFromArray($_SESSION['visitors_from']);
  $to = DrupalDateTime::createFromArray($_SESSION['visitors_to']);
  $form = array();
  $form['visitors_date_filter'] = array(
    '#collapsed' => FALSE,
    '#collapsible' => FALSE,
    '#description' => t('Choose date range'),
    '#title' => t('Date filter'),
    '#type' => 'fieldset',
  );
  $form['visitors_date_filter']['from'] = array(
    '#date_part_order' => $this
      ->_getOrder(),
    '#date_timezone' => date_default_timezone_get(),
    '#default_value' => $from,
    '#element_validate' => array(
      array(
        $this,
        'datelistValidate',
      ),
    ),
    '#process' => array(
      array(
        $this,
        'formProcessDatelist',
      ),
    ),
    '#title' => t('From'),
    '#type' => 'datelist',
    '#value_callback' => array(
      $this,
      'datelistValueCallback',
    ),
  );
  $form['visitors_date_filter']['to'] = array(
    '#date_part_order' => $this
      ->_getOrder(),
    '#date_timezone' => date_default_timezone_get(),
    '#default_value' => $to,
    '#element_validate' => array(
      array(
        $this,
        'datelistValidate',
      ),
    ),
    '#process' => array(
      array(
        $this,
        'formProcessDatelist',
      ),
    ),
    '#title' => t('To'),
    '#type' => 'datelist',
    '#value_callback' => array(
      $this,
      'datelistValueCallback',
    ),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}