function StringArgument::getFormula

Same name in other branches
  1. 9 core/modules/views/src/Plugin/views/argument/StringArgument.php \Drupal\views\Plugin\views\argument\StringArgument::getFormula()
  2. 8.9.x core/modules/views/src/Plugin/views/argument/StringArgument.php \Drupal\views\Plugin\views\argument\StringArgument::getFormula()
  3. 10 core/modules/views/src/Plugin/views/argument/StringArgument.php \Drupal\views\Plugin\views\argument\StringArgument::getFormula()

Get the formula for this argument.

$this->ensureMyTable() MUST have been called prior to this.

2 calls to StringArgument::getFormula()
StringArgument::query in core/modules/views/src/Plugin/views/argument/StringArgument.php
Build the query based upon the formula.
StringArgument::summaryQuery in core/modules/views/src/Plugin/views/argument/StringArgument.php
Build the summary query based on a string.

File

core/modules/views/src/Plugin/views/argument/StringArgument.php, line 184

Class

StringArgument
Argument handler for string.

Namespace

Drupal\views\Plugin\views\argument

Code

public function getFormula() {
    $formula = "SUBSTRING({$this->tableAlias}.{$this->realField}, 1, " . intval($this->options['limit']) . ")";
    if ($this->options['case'] != 'none') {
        // Support case-insensitive substring comparisons for SQLite by using the
        // 'NOCASE_UTF8' collation.
        // @see Drupal\sqlite\Driver\Database\sqlite\Connection::open()
        if (Database::getConnection()->databaseType() == 'sqlite') {
            $formula .= ' COLLATE NOCASE_UTF8';
        }
        // Support case-insensitive substring comparisons for PostgreSQL by
        // converting the formula to lowercase.
        if (Database::getConnection()->databaseType() == 'pgsql') {
            $formula = 'LOWER(' . $formula . ')';
        }
    }
    return $formula;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.