function StatisticsLastCommentName::query
Same name in this branch
- 10 core/modules/comment/src/Plugin/views/sort/StatisticsLastCommentName.php \Drupal\comment\Plugin\views\sort\StatisticsLastCommentName::query()
Same name in other branches
- 9 core/modules/comment/src/Plugin/views/sort/StatisticsLastCommentName.php \Drupal\comment\Plugin\views\sort\StatisticsLastCommentName::query()
- 9 core/modules/comment/src/Plugin/views/field/StatisticsLastCommentName.php \Drupal\comment\Plugin\views\field\StatisticsLastCommentName::query()
- 8.9.x core/modules/comment/src/Plugin/views/sort/StatisticsLastCommentName.php \Drupal\comment\Plugin\views\sort\StatisticsLastCommentName::query()
- 8.9.x core/modules/comment/src/Plugin/views/field/StatisticsLastCommentName.php \Drupal\comment\Plugin\views\field\StatisticsLastCommentName::query()
- 11.x core/modules/comment/src/Plugin/views/sort/StatisticsLastCommentName.php \Drupal\comment\Plugin\views\sort\StatisticsLastCommentName::query()
- 11.x core/modules/comment/src/Plugin/views/field/StatisticsLastCommentName.php \Drupal\comment\Plugin\views\field\StatisticsLastCommentName::query()
Overrides FieldPluginBase::query
File
-
core/
modules/ comment/ src/ Plugin/ views/ field/ StatisticsLastCommentName.php, line 38
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');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.