function StatisticsLastCommentName::query

Same name in this branch
  1. 11.x core/modules/comment/src/Plugin/views/field/StatisticsLastCommentName.php \Drupal\comment\Plugin\views\field\StatisticsLastCommentName::query()
Same name and namespace in other branches
  1. 9 core/modules/comment/src/Plugin/views/sort/StatisticsLastCommentName.php \Drupal\comment\Plugin\views\sort\StatisticsLastCommentName::query()
  2. 9 core/modules/comment/src/Plugin/views/field/StatisticsLastCommentName.php \Drupal\comment\Plugin\views\field\StatisticsLastCommentName::query()
  3. 8.9.x core/modules/comment/src/Plugin/views/sort/StatisticsLastCommentName.php \Drupal\comment\Plugin\views\sort\StatisticsLastCommentName::query()
  4. 8.9.x core/modules/comment/src/Plugin/views/field/StatisticsLastCommentName.php \Drupal\comment\Plugin\views\field\StatisticsLastCommentName::query()
  5. 10 core/modules/comment/src/Plugin/views/sort/StatisticsLastCommentName.php \Drupal\comment\Plugin\views\sort\StatisticsLastCommentName::query()
  6. 10 core/modules/comment/src/Plugin/views/field/StatisticsLastCommentName.php \Drupal\comment\Plugin\views\field\StatisticsLastCommentName::query()

Overrides SortPluginBase::query

File

core/modules/comment/src/Plugin/views/sort/StatisticsLastCommentName.php, line 28

Class

StatisticsLastCommentName
Sort handler, sorts by last comment name which can be in 2 different fields.

Namespace

Drupal\comment\Plugin\views\sort

Code

public function query() {
    $this->ensureMyTable();
    $definition = [
        'table' => 'users_field_data',
        'field' => 'uid',
        'left_table' => 'comment_entity_statistics',
        'left_field' => 'last_comment_uid',
    ];
    $join = \Drupal::service('plugin.manager.views.join')->createInstance('standard', $definition);
    // @todo this might be safer if we had an ensure_relationship rather than guessing
    // the table alias. Though if we did that we'd be guessing the relationship name
    // so that doesn't matter that much.
    $this->user_table = $this->query
        ->ensureTable('ces_users', $this->relationship, $join);
    $this->user_field = $this->query
        ->addField($this->user_table, 'name');
    // Add the field.
    $this->query
        ->addOrderBy(NULL, "LOWER(COALESCE({$this->user_table}.name, {$this->tableAlias}.{$this->field}))", $this->options['order'], $this->tableAlias . '_' . $this->field);
}

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