public static function HandlerBase::breakPhrase

Breaks x,y,z and x+y+z into an array. Numeric only.

Parameters

string $str: The string to parse.

Drupal\views\Plugin\views\HandlerBase|null $handler: The handler object to use as a base. If not specified one will be created.

Return value

Drupal\views\Plugin\views\HandlerBase|stdClass $handler The new handler object.

6 calls to HandlerBase::breakPhrase()
HandlerTest::testBreakPhrase in drupal/core/modules/views/lib/Drupal/views/Tests/Handler/HandlerTest.php
Tests Drupal\views\Plugin\views\HandlerBase::breakPhrase() function.
IndexTidDepth::query in drupal/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/argument/IndexTidDepth.php
Set up the query for this argument.
ManyToOne::query in drupal/core/modules/views/lib/Drupal/views/Plugin/views/argument/ManyToOne.php
Set up the query for this argument.
ManyToOne::title in drupal/core/modules/views/lib/Drupal/views/Plugin/views/argument/ManyToOne.php
Get the title this argument will assign the view, given the argument.
Numeric::query in drupal/core/modules/views/lib/Drupal/views/Plugin/views/argument/Numeric.php
Set up the query for this argument.

... See full list

File

drupal/core/modules/views/lib/Drupal/views/Plugin/views/HandlerBase.php, line 719
Definition of Drupal\views\Plugin\views\HandlerBase.

Class

HandlerBase

Namespace

Drupal\views\Plugin\views

Code

public static function breakPhrase($str, &$handler = NULL) {
  if (!$handler) {
    $handler = new \stdClass();
  }

  // Set up defaults:
  if (!isset($handler->value)) {
    $handler->value = array();
  }
  if (!isset($handler->operator)) {
    $handler->operator = 'or';
  }
  if (empty($str)) {
    return $handler;
  }
  if (preg_match('/^([0-9]+[+ ])+[0-9]+$/', $str)) {

    // The '+' character in a query string may be parsed as ' '.
    $handler->operator = 'or';
    $handler->value = preg_split('/[+ ]/', $str);
  }
  elseif (preg_match('/^([0-9]+,)*[0-9]+$/', $str)) {
    $handler->operator = 'and';
    $handler->value = explode(',', $str);
  }

  // Keep an 'error' value if invalid strings were given.
  if (!empty($str) && (empty($handler->value) || !is_array($handler->value))) {
    $handler->value = array(
      -1,
    );
    return $handler;
  }

  // Doubly ensure that all values are numeric only.
  foreach ($handler->value as $id => $value) {
    $handler->value[$id] = intval($value);
  }
  return $handler;
}