3 namespace Drupal\comment\Plugin\views\sort;
5 use Drupal\views\Plugin\views\sort\SortPluginBase;
8 * Sort handler to sort by last comment name which might be in 2 different
11 * @ingroup views_sort_handlers
13 * @ViewsSort("comment_ces_last_comment_name")
15 class StatisticsLastCommentName extends SortPluginBase {
17 public function query() {
18 $this->ensureMyTable();
20 'table' => 'users_field_data',
22 'left_table' => 'comment_entity_statistics',
23 'left_field' => 'last_comment_uid',
25 $join = \Drupal::service('plugin.manager.views.join')->createInstance('standard', $definition);
27 // @todo this might be safer if we had an ensure_relationship rather than guessing
28 // the table alias. Though if we did that we'd be guessing the relationship name
29 // so that doesn't matter that much.
30 $this->user_table = $this->query->ensureTable('ces_users', $this->relationship, $join);
31 $this->user_field = $this->query->addField($this->user_table, 'name');
34 $this->query->addOrderBy(NULL, "LOWER(COALESCE($this->user_table.name, $this->tableAlias.$this->field))", $this->options['order'], $this->tableAlias . '_' . $this->field);