diff --git a/core/modules/views/src/Plugin/views/argument/StringArgument.php b/core/modules/views/src/Plugin/views/argument/StringArgument.php index 33da84f207c9db1c7bb34aa31804ec41ff8e185e..d417e811280e1938564e33451016e4e0ff4abb34 100644 --- a/core/modules/views/src/Plugin/views/argument/StringArgument.php +++ b/core/modules/views/src/Plugin/views/argument/StringArgument.php @@ -7,6 +7,7 @@ namespace Drupal\views\Plugin\views\argument; +use Drupal\Component\Utility\Unicode; use Drupal\Core\Database\Database; use Drupal\Core\Form\FormStateInterface; use Drupal\views\ViewExecutable; @@ -179,11 +180,19 @@ protected function summaryQuery() { public function getFormula() { $formula = "SUBSTRING($this->tableAlias.$this->realField, 1, " . intval($this->options['limit']) . ")"; - // Support case-insensitive substring comparisons for SQLite by using the - // 'NOCASE_UTF8' collation. - // @see Drupal\Core\Database\Driver\sqlite\Connection::open() - if (Database::getConnection()->databaseType() == 'sqlite' && $this->options['case'] != 'none') { - $formula .= ' COLLATE NOCASE_UTF8'; + if ($this->options['case'] != 'none') { + // Support case-insensitive substring comparisons for SQLite by using the + // 'NOCASE_UTF8' collation. + // @see Drupal\Core\Database\Driver\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; } @@ -205,6 +214,14 @@ public function query($group_by = FALSE) { $this->operator = 'or'; } + // Support case-insensitive substring comparisons for PostgreSQL by + // converting the arguments to lowercase. + if ($this->options['case'] != 'none' && Database::getConnection()->databaseType() == 'pgsql') { + foreach ($this->value as $key => $value) { + $this->value[$key] = Unicode::strtolower($value); + } + } + if (!empty($this->definition['many to one'])) { if (!empty($this->options['glossary'])) { $this->helper->formula = TRUE; @@ -266,6 +283,12 @@ public function getSortName() { } function title() { + // Support case-insensitive title comparisons for PostgreSQL by converting + // the title to lowercase. + if ($this->options['case'] != 'none' && Database::getConnection()->databaseType() == 'pgsql') { + $this->options['case'] = 'lower'; + } + $this->argument = $this->caseTransform($this->argument, $this->options['case']); if (!empty($this->options['transform_dash'])) { $this->argument = strtr($this->argument, '-', ' ');