Thread.php

Same filename in other branches
  1. 9 core/modules/comment/src/Plugin/views/sort/Thread.php
  2. 8.9.x core/modules/comment/src/Plugin/views/sort/Thread.php
  3. 11.x core/modules/comment/src/Plugin/views/sort/Thread.php

Namespace

Drupal\comment\Plugin\views\sort

File

core/modules/comment/src/Plugin/views/sort/Thread.php

View source
<?php

namespace Drupal\comment\Plugin\views\sort;

use Drupal\views\Attribute\ViewsSort;
use Drupal\views\Plugin\views\sort\SortPluginBase;

/**
 * Sort handler for ordering by thread.
 *
 * @ingroup views_sort_handlers
 */
class Thread extends SortPluginBase {
    public function query() {
        $this->ensureMyTable();
        // See \Drupal\comment\CommentStorage::loadThread() for an explanation of
        // the thinking behind this sort.
        if ($this->options['order'] == 'DESC') {
            $this->query
                ->addOrderBy($this->tableAlias, $this->realField, $this->options['order']);
        }
        else {
            $alias = $this->tableAlias . '_' . $this->realField . 'asc';
            // @todo is this secure?
            $this->query
                ->addOrderBy(NULL, "SUBSTRING({$this->tableAlias}.{$this->realField}, 1, (LENGTH({$this->tableAlias}.{$this->realField}) - 1))", $this->options['order'], $alias);
        }
    }

}

Classes

Title Deprecated Summary
Thread Sort handler for ordering by thread.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.