You are here

function mixitup_views_filters_form in MixItUp Views 7

Filters form.

1 string reference to 'mixitup_views_filters_form'
template_preprocess_views_view_mixitup in ./mixitup_views.module
Preprocess function for views_view_mixitup.tpl.php.

File

./mixitup_views.module, line 364
Provides a Views style plugin for displaying content with Mixitup filtering.

Code

function mixitup_views_filters_form($form, &$form_state, $options) {
  $filters =& drupal_static('mixitup_views_populate_filters');
  $form = array();
  if (isset($filters)) {
    foreach ($filters as $vid => $terms) {

      // Show only selected vocabularies.
      if ($options['restrict_vocab'] == 1 && (!isset($options['restrict_vocab_ids'][$vid]) || $options['restrict_vocab_ids'][$vid] == 0)) {
        unset($filters[$vid]);
        continue;
      }

      // If all nodes have just one term tagged, it doesn't make sense
      // to show a term and clear filters link.
      if (count($terms) < 2) {
        unset($filters[$vid]);
        continue;
      }
      $vocab = taxonomy_vocabulary_load($vid);
      $terms = mixitup_views_filter_terms($terms);
      if (isset($options['filter_type'])) {
        switch ($options['filter_type']) {
          case 'checkboxes':
            $form['filter_' . $vid] = array(
              '#type' => 'checkboxes',
              '#title' => $vocab->name,
              '#options' => $terms,
              '#attributes' => array(
                'class' => array(
                  'mixitup_views_filter',
                ),
                'vid' => $vid,
              ),
              '#multiple' => TRUE,
            );
            break;
          case 'select':
            $form['filter_' . $vid] = array(
              '#type' => 'select',
              '#title' => $vocab->name,
              '#options' => array(
                '' => t('All'),
              ) + $terms,
              '#attributes' => array(
                'class' => array(
                  'mixitup_views_filter',
                ),
                'vid' => $vid,
              ),
              '#multiple' => FALSE,
            );
            break;
        }
      }
    }
    if ($filters) {
      $form['reset'] = array(
        '#markup' => l(t('Clear Filters'), '', array(
          'fragment' => 'reset',
          'external' => TRUE,
          'attributes' => array(
            'id' => 'reset',
          ),
        )),
      );
    }
  }
  if (isset($options['use_sort']) && $options['use_sort'] == 1 && isset($options['sorts'])) {
    $form['sort'] = array(
      '#markup' => theme('mixitup_views_sorting', array(
        'sorts' => $options['sorts'],
      )),
    );
  }
  return $form;
}