You are here

function global_filter_finalise_form in Views Global Filter 8

Same name and namespace in other branches
  1. 7 global_filter.widgets.inc \global_filter_finalise_form()

Complete the form.

Parameters

array $form: the form to complete

int $block_number: the block number

1 call to global_filter_finalise_form()
global_filter_submission_form in ./global_filter.widgets.inc
Creates the global selector widgets, e.g. drop-down, radio-boxes, links...

File

./global_filter.widgets.inc, line 303
global_filter.widgets.inc

Code

function global_filter_finalise_form(&$form, $block_number) {

  // Preserve filter order as selected on the block configuration page.
  $num_filters = 0;
  foreach ($form as $key => &$filter_element) {
    if (drupal_substr($key, 0, 1) != '#') {
      $filter_element['#weight'] = ++$num_filters;
    }
  }
  $submit_required = $button_required = FALSE;
  foreach ($filters = global_filter_get_filters_for_block($block_number) as $key => $filter) {
    $name = $filter['name'];
    $filter_delta = GLOBAL_FILTER_FILTER_KEY_PREFIX . $key;

    // We're adding a class rather than an id as it needs to be attached to all
    // of the <input>'s of each sequence of check boxes or radio buttons.
    $form[$name]['#attributes']['class'][] = drupal_html_class("{$filter_delta}-{$name}");
    $confirm_question = global_filter_get_parameter($key, 'confirm_question');
    $autosubmit = global_filter_get_parameter($key, 'set_on_select');
    if ($filter['widget'] != 'links') {
      $submit_required = TRUE;
      if (!$autosubmit) {
        $button_required = TRUE;
      }
    }
    if ($confirm_question || $autosubmit) {
      drupal_add_js(array(
        $filter_delta => array(
          drupal_html_class("{$filter_delta}-{$name}"),
          $confirm_question,
          $autosubmit,
        ),
      ), 'setting');
      $form[$name]['#attached']['js'][] = drupal_get_path('module', 'global_filter') . '/js/global_filter_all.js';
    }
  }
  if ($submit_required) {
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Set'),
      '#submit' => array(
        'global_filter_set_form_on_session',
      ),
      '#attributes' => array(
        'class' => array(
          drupal_html_class('global-filter-set-' . ($num_filters > 1 ? 'all' : $filter['widget'])),
        ),
      ),
      '#weight' => ++$num_filters,
    );
    if (!$button_required) {

      // Suppress the 'Set' submit button defined above.
      $form['submit']['#attributes']['style'][] = 'display:none';
    }
  }
}