Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. StatisticsLastCommentName.php

function StatisticsLastCommentName::query

Same name in this branch
  1. 11.1.x core/modules/comment/src/Plugin/views/sort/StatisticsLastCommentName.php \Drupal\comment\Plugin\views\sort\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\field

Code

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');
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal