Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. HandlerBase.php

function HandlerBase::breakString

Overrides ViewsHandlerInterface::breakString

4 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.
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 817

Class

HandlerBase
Base class for Views handler plugins.

Namespace

Drupal\views\Plugin\views

Code

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(FilterArray::removeEmptyStrings($value));
    if ($force_int) {
        $value = array_map('intval', $value);
    }
    return (object) [
        'value' => $value,
        'operator' => $operator,
    ];
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal