You are here

class apachesolr_views_handler_argument_optionwidget in Apache Solr Views 6

@file Provides an argument handler for optionwidgets so they can use their allowed values

Hierarchy

Expanded class hierarchy of apachesolr_views_handler_argument_optionwidget

1 string reference to 'apachesolr_views_handler_argument_optionwidget'
apachesolr_views_views_data in ./apachesolr_views.views.inc
Implementation of hook_views_data().

File

handlers/apachesolr_views_handler_argument_optionwidget.inc, line 7
Provides an argument handler for optionwidgets so they can use their allowed values

View source
class apachesolr_views_handler_argument_optionwidget extends apachesolr_views_handler_argument {

  /**
   * Override query() and do some fancy manipulation of the argument
   * so that it is boiled down to the actual field value
   * instead of the nice title
   */
  function query() {
    $field = $this->definition['cck_field'];
    foreach (content_allowed_values(content_fields($field['field_name'])) as $allowed_value => $nice_text) {
      $options[$allowed_value] = strtolower(str_replace(' ', '-', $nice_text));
    }
    if (!empty($this->options['break_phrase'])) {
      $arguments = explode(',', $this
        ->get_value());
    }
    else {
      $arguments = array(
        $this
          ->get_value(),
      );
    }

    // time to set the arguments to something new
    $new_arguments = array();
    foreach ($arguments as $value) {
      $key = array_search($value, $options);
      if (!empty($key)) {
        $new_arguments[] = $key;
      }
      else {

        // TODO: do we need to do something here?
      }
    }
    foreach ($new_arguments as $facet_value) {
      $this->query
        ->add_filter($this->real_field, apachesolr_views_query::escape_term($facet_value));
    }
  }

  /**
   * Get the title this argument will assign the view, given the argument.
   */
  function title() {
    $field = $this->definition['cck_field'];
    foreach (content_allowed_values(content_fields($field['field_name'])) as $allowed_value => $nice_text) {
      $valid_path = strtolower(str_replace(' ', '-', $nice_text));
      if ($this->argument == $valid_path) {
        return check_plain($nice_text);
      }
    }
    return check_plain($this->argument);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
apachesolr_views_handler_argument::default_actions function Provide a list of default behaviors for this argument if the argument is not present.
apachesolr_views_handler_argument::options_form function
apachesolr_views_handler_argument::option_definition function
apachesolr_views_handler_argument_optionwidget::query function Override query() and do some fancy manipulation of the argument so that it is boiled down to the actual field value instead of the nice title Overrides apachesolr_views_handler_argument::query
apachesolr_views_handler_argument_optionwidget::title function Get the title this argument will assign the view, given the argument.