You are here

public function BannerFilterForm::buildForm in Dynamic Banner 8

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

File

src/forms/BannerFilterForm.php, line 17

Class

BannerFilterForm

Namespace

Drupal\dynamic_banner\forms

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $_SESSION = array();
  $filters = self::dynamic_banner_filters();
  $form['filters'] = array(
    '#type' => 'fieldset',
    '#title' => t('Filter dynamic banner'),
    '#collapsible' => TRUE,
    '#collapsed' => empty($_SESSION['dynamic_banner_filter']),
  );
  if (!empty($filters)) {
    foreach ($filters as $key => $filter) {
      $form['filters']['status'][$key] = array(
        '#title' => $filter['title'],
        '#type' => 'select',
        '#multiple' => TRUE,
        '#size' => 8,
        '#options' => $filter['options'],
      );
      if (!empty($_SESSION['dynamic_banner_filter'][$key])) {
        $form['filters']['status'][$key]['#default_value'] = $_SESSION['dynamic_banner_filter'][$key];
      }
    }
  }
  $form['filters']['actions'] = array(
    '#type' => 'actions',
    '#attributes' => array(
      'class' => array(
        'container-inline',
      ),
    ),
  );
  $form['filters']['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Filter'),
  );
  if (!empty($_SESSION['dynamic_banner_filter'])) {
    $form['filters']['actions']['reset'] = array(
      '#type' => 'button',
      '#button_type' => 'reset',
      '#value' => t('Clear -'),
      '#weight' => 9,
      '#validate' => array(),
      '#attributes' => array(
        'onclick' => 'this.form.reset(); return false;',
      ),
    );
  }
  return $form;
}