function QueryAggregate::createSqlAlias

Same name in other branches
  1. 9 core/lib/Drupal/Core/Entity/Query/Sql/QueryAggregate.php \Drupal\Core\Entity\Query\Sql\QueryAggregate::createSqlAlias()
  2. 8.9.x core/lib/Drupal/Core/Entity/Query/Sql/QueryAggregate.php \Drupal\Core\Entity\Query\Sql\QueryAggregate::createSqlAlias()
  3. 10 core/lib/Drupal/Core/Entity/Query/Sql/QueryAggregate.php \Drupal\Core\Entity\Query\Sql\QueryAggregate::createSqlAlias()

Builds a sql alias as expected in the result.

Parameters

string $field: The field as passed in by the caller.

string $sql_field: The sql field as returned by getSqlField.

Return value

string The SQL alias expected in the return value. The dots in $sql_field are replaced with underscores and if a default fallback to .value happened, the _value is stripped.

1 call to QueryAggregate::createSqlAlias()
QueryAggregate::addGroupBy in core/lib/Drupal/Core/Entity/Query/Sql/QueryAggregate.php
Adds the groupby values to the actual query.

File

core/lib/Drupal/Core/Entity/Query/Sql/QueryAggregate.php, line 154

Class

QueryAggregate
The SQL storage entity query aggregate class.

Namespace

Drupal\Core\Entity\Query\Sql

Code

public function createSqlAlias($field, $sql_field) {
    $alias = str_replace('.', '_', $sql_field);
    // If the alias contains of field_*_value remove the _value at the end.
    if (str_starts_with($alias, 'field_') && !str_ends_with($field, '_value') && str_ends_with($alias, '_value')) {
        $alias = substr($alias, 0, -6);
    }
    return $alias;
}

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