public static function HandlerBase::breakString in Drupal 9
Same name and namespace in other branches
- 8 core/modules/views/src/Plugin/views/HandlerBase.php \Drupal\views\Plugin\views\HandlerBase::breakString()
Breaks x,y,z and x+y+z into an array.
Parameters
string $str: The string to split.
bool $force_int: Enforce a numeric check.
Return value
object A stdClass object containing value and operator properties.
Overrides ViewsHandlerInterface::breakString
5 calls to HandlerBase::breakString()
- ArgumentPluginBase::unpackArgumentValue in core/
modules/ views/ src/ Plugin/ views/ argument/ ArgumentPluginBase.php - Splits an argument into value and operator properties on this instance.
- HandlerTest::testBreakString in core/
modules/ views/ tests/ src/ Functional/ Handler/ HandlerTest.php - Tests the breakString method.
- IndexTidDepth::query in core/
modules/ taxonomy/ src/ Plugin/ views/ argument/ IndexTidDepth.php - Set up the query for this argument.
- NumericArgument::query in core/
modules/ views/ src/ Plugin/ views/ argument/ NumericArgument.php - Set up the query for this argument.
- NumericArgument::title in core/
modules/ views/ src/ Plugin/ views/ argument/ NumericArgument.php - Get the title this argument will assign the view, given the argument.
File
- core/
modules/ views/ src/ Plugin/ views/ HandlerBase.php, line 725
Class
- HandlerBase
- Base class for Views handler plugins.
Namespace
Drupal\views\Plugin\viewsCode
public static function breakString($str, $force_int = FALSE) {
$operator = NULL;
$value = [];
// Determine if the string has 'or' operators (plus signs) or 'and'
// operators (commas) and split the string accordingly.
if (preg_match('/^([\\w0-9-_\\.]+[+ ]+)+[\\w0-9-_\\.]+$/u', $str)) {
// The '+' character in a query string may be parsed as ' '.
$operator = 'or';
$value = preg_split('/[+ ]/', $str);
}
elseif (preg_match('/^([\\w0-9-_\\.]+[, ]+)*[\\w0-9-_\\.]+$/u', $str)) {
$operator = 'and';
$value = explode(',', $str);
}
// Filter any empty matches (Like from '++' in a string) and reset the
// array keys. 'strlen' is used as the filter callback so we do not lose
// 0 values (would otherwise evaluate == FALSE).
$value = array_values(array_filter($value, 'strlen'));
if ($force_int) {
$value = array_map('intval', $value);
}
return (object) [
'value' => $value,
'operator' => $operator,
];
}