3 namespace Drupal\comment\Plugin\views\sort;
5 use Drupal\views\Plugin\views\sort\SortPluginBase;
8 * Sort handler for ordering by thread.
10 * @ingroup views_sort_handlers
12 * @ViewsSort("comment_thread")
14 class Thread extends SortPluginBase {
16 public function query() {
17 $this->ensureMyTable();
19 //Read comment_render() in comment.module for an explanation of the
20 //thinking behind this sort.
21 if ($this->options['order'] == 'DESC') {
22 $this->query->addOrderBy($this->tableAlias, $this->realField, $this->options['order']);
25 $alias = $this->tableAlias . '_' . $this->realField . 'asc';
26 //@todo is this secure?
27 $this->query->addOrderBy(NULL, "SUBSTRING({$this->tableAlias}.{$this->realField}, 1, (LENGTH({$this->tableAlias}.{$this->realField}) - 1))", $this->options['order'], $alias);