You are here

protected function SearchApiDate::unpackArgumentValue in Search API 8

Splits an argument into value and operator properties on this instance.

Parameters

bool $force_int: Enforce that values should be numeric.

Overrides ArgumentPluginBase::unpackArgumentValue

File

src/Plugin/views/argument/SearchApiDate.php, line 159

Class

SearchApiDate
Defines a contextual filter for conditions on date fields.

Namespace

Drupal\search_api\Plugin\views\argument

Code

protected function unpackArgumentValue($force_int = FALSE) {

  // Set up the defaults.
  if (!isset($this->value)) {
    $this->value = [];
  }
  if (!isset($this->operator)) {
    $this->operator = 'or';
  }
  if (empty($this->argument)) {
    return;
  }
  if (preg_match('/^([-\\d;:\\s]+\\+)*[-\\d;:\\s]+$/', $this->argument)) {

    // The '+' character in a query string may be parsed as ' '.
    $this->value = explode('+', $this->argument);
  }
  elseif (preg_match('/^([-\\d;:\\s]+,)*[-\\d;:\\s]+$/', $this->argument)) {
    $this->operator = 'and';
    $this->value = explode(',', $this->argument);
  }

  // Keep an "error" value if invalid strings were given.
  if (!empty($this->argument) && (empty($this->value) || !is_array($this->value))) {
    $this->value = FALSE;
  }
}