You are here

class global_filter_plugin_argument_default_global_filter_view in Views Global Filter 8

Same name and namespace in other branches
  1. 6 views/global_filter_plugin_argument_default_global_filter_view.inc \global_filter_plugin_argument_default_global_filter_view
  2. 7 views/global_filter_plugin_argument_default_global_filter_view.inc \global_filter_plugin_argument_default_global_filter_view

Default argument plugin to extract the View filter values set for this contextual filter.

Hierarchy

Expanded class hierarchy of global_filter_plugin_argument_default_global_filter_view

1 string reference to 'global_filter_plugin_argument_default_global_filter_view'
global_filter_views_plugins in views/global_filter.views.inc
Implements hook_views_plugins().

File

views/global_filter_plugin_argument_default_global_filter_view.inc, line 11
Contains the Global Filter default argument plugin (view).

View source
class global_filter_plugin_argument_default_global_filter_view extends views_plugin_argument_default {

  /**
   * Define the option.
   */
  public function option_definition() {
    $options = parent::option_definition();
    $options['global_filter_view'] = array(
      'default' => '',
    );
    return $options;
  }

  /**
   * Build the options form.
   */
  public function options_form(&$form, &$form_state) {
    $form['global_filter_view'] = array(
      '#type' => 'select',
      '#title' => t('View providing default value'),
      '#options' => global_filter_get_used_view_names(),
      '#default_value' => $this->options['global_filter_view'],
      '#description' => t('Select the global filter view(s) that will provide the default value for this contextual filter.'),
      // See [#1618302].
      '#multiple' => TRUE,
    );
  }

  /**
   * Get argument.
   */
  public function get_argument() {
    $arg = $view_names = $this->options['global_filter_view'];
    if (!empty($view_names)) {
      if (!is_array($view_names)) {
        $view_names = array(
          $view_names,
        );
      }
      $arg = array();
      foreach ($view_names as $view_name) {
        $value = global_filter_get_session_value($view_name);
        if (isset($value)) {
          if (is_array($value)) {
            $arg = array_merge($arg, $value);
          }
          else {
            $arg[] = $value;
          }
        }
      }
      $arg = array_filter($arg);
    }
    if (empty($arg)) {

      // For e.g. 'all'.
      $arg = $this->argument->options['exception']['value'];
    }

    // If the argument is multi-valued, ie multi-select box or check boxes,
    // string the values together separated by plus-signs.
    // Note this requires the user to tick "Allow multiple values" after
    // expanding the "More" fieldset on the Contextual Filter configuration
    // panel. Otherwise only the first of the values will used.
    return is_array($arg) ? implode('+', $arg) : $arg;
  }

}

Members