You are here

class global_filter_plugin_argument_default_global_filter_field in Views Global Filter 7

Same name and namespace in other branches
  1. 8 views/global_filter_plugin_argument_default_global_filter_field.inc \global_filter_plugin_argument_default_global_filter_field
  2. 6 views/global_filter_plugin_argument_default_global_filter_field.inc \global_filter_plugin_argument_default_global_filter_field

Default argument plugin to extract the global filter value set for this contextual filter.

If the argument is a date or date range, it must be in this format: YYYY-MM-DD--YYYY-MM-DD Note the double hyphen.

If the Contextual Range Filter modules is enabled, ranges may also be used for numbers (integers, floats), lists, taxonomy terms, node and user ids...

Hierarchy

Expanded class hierarchy of global_filter_plugin_argument_default_global_filter_field

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

File

views/global_filter_plugin_argument_default_global_filter_field.inc, line 17
Contains the Global Filter default argument plugin (field).

View source
class global_filter_plugin_argument_default_global_filter_field extends views_plugin_argument_default {

  /**
   * Define the one option we offer.
   */
  public function option_definition() {
    $options = parent::option_definition();
    $options['break_phrase_and'] = array(
      'default' => FALSE,
      'bool' => TRUE,
    );
    return $options;
  }

  /**
   * Build the option form.
   */
  function options_form(&$form, &$form_state) {
    parent::options_form($form, $form_state);
    $form['break_phrase_and'] = array(
      '#type' => 'checkbox',
      '#title' => t('Process multiple filter values in <em>all of</em> (AND) rather than <em>one of</em> (OR) mode.'),
      '#description' => t('Applies only when <strong>Allow multiple values</strong> is ticked in the <strong>More</strong> fieldset below.'),
      '#default_value' => !empty($this->options['break_phrase_and']),
    );
  }

  /**
   * Get argument.
   */
  public function get_argument() {
    $field_name = $views_field_name = $this->argument->field;

    // Where $views_field_name refers to a field it equals one of:
    // '<field_name>_value', '<field_name>_tid' or '<field_name>_fid'
    $exception_value = $this->argument->options['exception']['value'];
    if (!($filter_key = global_filter_key_by_name($views_field_name))) {

      // Not found as a node property, maybe it's a field or taxonomy term.
      // "Has taxonomy term ID" shows up with $views_field_name == 'tid'
      if (isset($this->argument->definition['field_name'])) {
        $field_name = $this->argument->definition['field_name'];
        $filter_key = global_filter_key_by_name($field_name);
      }
      else {
        $filter_key = FALSE;
      }
    }
    if ($filter_key) {
      $arg = global_filter_get_session_value($field_name);
      if (isset($arg) && $arg != '' && $arg != array(
        '',
      )) {

        // Don't reduce array(0) to empty.
        if (is_array($arg) && $arg != array(
          0,
        )) {

          // Removing empty entries may not be right when filter is numeric, i.e
          // a single digit 0 will be removed. However 00 will be interpreted
          // correctly as zero.
          $arg = array_filter($arg);

          // For Hierarchical select: always use deepest term. For other fields
          // it doesn't matter.
          $arg = array_reverse($arg);
          if (empty($arg)) {
            return $exception_value;
          }
        }
        if (is_string($arg)) {
          if ($field = field_info_field($field_name)) {

            // Handle taxonomy terms and list fields that were configured to
            // render as text fields. Convert the entered value back to a tid or
            // list key. Accept a string of values separated by plus signs.
            $args = explode('+', $arg);
            if ($field['type'] == 'taxonomy_term_reference') {
              $arg = array();
              $vocabulary = $field['settings']['allowed_values'][0]['vocabulary'];
              foreach ($args as $value) {
                $arg[] = global_filter_get_tid($value, $vocabulary);
              }
            }
            elseif (strpos($field['type'], 'list_') === 0) {
              $arg = array();
              foreach ($args as $value) {
                $arg[] = global_filter_get_field_value_key($field, $value);
              }
            }
          }
        }
      }
      else {
        $arg = $exception_value;
      }

      // If the argument is multi-valued (combo-box, checkboxes or text field
      // with '+' or ',') string the values together separated by the appropiate
      // plus-sign (for OR, the default) or comma (for AND).
      // 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 be used.
      // Note:
      // Be careful with spaces: have seen "very cheap" interpreted as "cheap"
      $is_and = !empty($this->argument->options['break_phrase']) && !empty($this->options['break_phrase_and']);
      return is_array($arg) ? implode($is_and ? ',' : '+', $arg) : $arg;
    }

    // No filter key, field or node property not found.
    $view_name = empty($this->view->human_name) ? $this->view->name : $this->view->human_name;
    drupal_set_message(t('The view %view specifies a global filter field, %name, as its default contextual filter. However there is no associated <strong>Global Filter block</strong> for %name. Please configure a global filter <a href="admin/structure/block">here</a> or remove this contextual filter from the view.', array(
      '%view' => $view_name,
      '%name' => $views_field_name,
    )), 'warning', FALSE);
    return $exception_value;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
global_filter_plugin_argument_default_global_filter_field::get_argument public function Get argument. Overrides views_plugin_argument_default::get_argument
global_filter_plugin_argument_default_global_filter_field::options_form function Build the option form. Overrides views_plugin_argument_default::options_form
global_filter_plugin_argument_default_global_filter_field::option_definition public function Define the one option we offer. Overrides views_plugin_argument_default::option_definition
views_object::$definition public property Handler's definition.
views_object::$options public property Except for displays, options for the object will be held here. 1
views_object::altered_option_definition function Collect this handler's option definition and alter them, ready for use.
views_object::construct public function Views handlers use a special construct function. 4
views_object::destroy public function Destructor. 2
views_object::export_option public function 1
views_object::export_options public function
views_object::export_option_always public function Always exports the option, regardless of the default value.
views_object::options Deprecated public function Set default options on this object. 1
views_object::set_default_options public function Set default options.
views_object::set_definition public function Let the handler know what its full definition is.
views_object::unpack_options public function Unpack options over our existing defaults, drilling down into arrays so that defaults don't get totally blown away.
views_object::unpack_translatable public function Unpack a single option definition.
views_object::unpack_translatables public function Unpacks each handler to store translatable texts.
views_object::_set_option_defaults public function
views_plugin::$display public property The current used views display.
views_plugin::$plugin_name public property The plugin name of this plugin, for example table or full.
views_plugin::$plugin_type public property The plugin type of this plugin, for example style or query.
views_plugin::$view public property The top object of a view. Overrides views_object::$view 1
views_plugin::additional_theme_functions public function Provide a list of additional theme functions for the theme info page.
views_plugin::plugin_title public function Return the human readable name of the display.
views_plugin::query public function Add anything to the query that we might need to. 7
views_plugin::summary_title public function Returns the summary of the settings in the display. 8
views_plugin::theme_functions public function Provide a full list of possible theme templates used by this style.
views_plugin::validate public function Validate that the plugin is correct and can be saved. 3
views_plugin_argument_default::access public function Determine if the administrator has the privileges to use this plugin. 1
views_plugin_argument_default::check_access public function If we don't have access to the form but are showing it anyway, ensure that the form is safe and cannot be changed from user input.
views_plugin_argument_default::convert_options public function Convert options from the older style. 3
views_plugin_argument_default::init public function Initialize this plugin with the view and the argument it is linked to. 1
views_plugin_argument_default::options_submit public function Provide the default form form for submitting options. Overrides views_plugin::options_submit 1
views_plugin_argument_default::options_validate public function Provide the default form form for validating options. Overrides views_plugin::options_validate