NullSort.php in Views Sort Null Field 1.x
File
src/Plugin/views/sort/NullSort.php
View source
<?php
namespace Drupal\views_sort_null_field\Plugin\views\sort;
use Drupal\views\Plugin\views\sort\SortPluginBase;
class NullSort extends SortPluginBase {
public function query() {
$this
->ensureMyTable();
$alias = implode('_', [
$this->tableAlias,
$this->realField,
'is_null',
]);
$this->query
->addOrderBy(NULL, "ISNULL({$this->tableAlias}.{$this->realField})", $this->options['order'], $alias);
}
protected function sortOptions() {
return array(
'ASC' => $this
->t('Sort NULL last'),
'DESC' => $this
->t('Sort NULL first'),
);
}
public function adminSummary() {
if (!empty($this->options['exposed'])) {
return $this
->t('Exposed');
}
switch ($this->options['order']) {
case 'ASC':
case 'asc':
default:
return $this
->t('NULL last');
case 'DESC':
case 'desc':
return $this
->t('NULL first');
}
}
}
Classes
Name |
Description |
NullSort |
Basic sort handler for NULL values. |