Commit 69c99e6d authored by Owen Barton's avatar Owen Barton Committed by Damien McKenna
Browse files

Issue #1930472 by Owen Barton, Dean Reilly: Add exclude support to string...

Issue #1930472 by Owen Barton, Dean Reilly: Add exclude support to string contextual filter handler.
parent 535ff980
Loading
Loading
Loading
Loading
+13 −7
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ class views_handler_argument_string extends views_handler_argument {
    $options['path_case'] = array('default' => 'none');
    $options['transform_dash'] = array('default' => FALSE, 'bool' => TRUE);
    $options['break_phrase'] = array('default' => FALSE, 'bool' => TRUE);
    $options['not'] = array('default' => FALSE, 'bool' => TRUE);

    if (!empty($this->definition['many to one'])) {
      $options['add_table'] = array('default' => FALSE, 'bool' => TRUE);
@@ -132,6 +133,13 @@ class views_handler_argument_string extends views_handler_argument {
      '#default_value' => !empty($this->options['break_phrase']),
      '#fieldset' => 'more',
    );
    $form['not'] = array(
      '#type' => 'checkbox',
      '#title' => t('Exclude'),
      '#description' => t('If selected, the numbers entered for the filter will be excluded rather than limiting the view.'),
      '#default_value' => !empty($this->options['not']),
      '#fieldset' => 'more',
    );
  }

  /**
@@ -207,21 +215,19 @@ class views_handler_argument_string extends views_handler_argument {
    }

    if (count($this->value) > 1) {
      $operator = 'IN';
      $operator = empty($this->options['not']) ? 'IN' : 'NOT IN';
      $argument = $this->value;
    }
    else {
      $operator = '=';
      $operator = empty($this->options['not']) ? '=' : '!=';
    }

    if ($formula) {
      $placeholder = $this->placeholder();
      if ($operator == 'IN') {
        $field .= " IN($placeholder)";
      }
      else {
        $field .= ' = ' . $placeholder;
      if (count($this->value) > 1) {
        $placeholder = "($placeholder)";
      }
      $field .= " $operator $placeholder";
      $placeholders = array(
        $placeholder => $argument,
      );