public function StatisticsLastCommentName::query in Drupal 8
Same name in this branch
- 8 core/modules/comment/src/Plugin/views/sort/StatisticsLastCommentName.php \Drupal\comment\Plugin\views\sort\StatisticsLastCommentName::query()
- 8 core/modules/comment/src/Plugin/views/field/StatisticsLastCommentName.php \Drupal\comment\Plugin\views\field\StatisticsLastCommentName::query()
Same name and namespace in other branches
- 9 core/modules/comment/src/Plugin/views/field/StatisticsLastCommentName.php \Drupal\comment\Plugin\views\field\StatisticsLastCommentName::query()
Called to add the field to a query.
Overrides FieldPluginBase::query
File
- core/
modules/ comment/ src/ Plugin/ views/ field/ StatisticsLastCommentName.php, line 21
Class
- StatisticsLastCommentName
- Field handler to present the name of the last comment poster.
Namespace
Drupal\comment\Plugin\views\fieldCode
public function query() {
// last_comment_name only contains data if the user is anonymous. So we
// have to join in a specially related user table.
$this
->ensureMyTable();
// join 'users' to this table via vid
$definition = [
'table' => 'users_field_data',
'field' => 'uid',
'left_table' => 'comment_entity_statistics',
'left_field' => 'last_comment_uid',
'extra' => [
[
'field' => 'uid',
'operator' => '!=',
'value' => '0',
],
],
];
$join = \Drupal::service('plugin.manager.views.join')
->createInstance('standard', $definition);
// nes_user alias so this can work with the sort handler, below.
$this->user_table = $this->query
->ensureTable('ces_users', $this->relationship, $join);
$this->field_alias = $this->query
->addField(NULL, "COALESCE({$this->user_table}.name, {$this->tableAlias}.{$this->field})", $this->tableAlias . '_' . $this->field);
$this->user_field = $this->query
->addField($this->user_table, 'name');
$this->uid = $this->query
->addField($this->tableAlias, 'last_comment_uid');
}