You are here

Random.php in Drupal 9

File

core/modules/views/src/Plugin/views/sort/Random.php
View source
<?php

namespace Drupal\views\Plugin\views\sort;

use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Cache\UncacheableDependencyTrait;
use Drupal\Core\Form\FormStateInterface;

/**
 * Handle a random sort.
 *
 * @ViewsSort("random")
 */
class Random extends SortPluginBase implements CacheableDependencyInterface {
  use UncacheableDependencyTrait;

  /**
   * {@inheritdoc}
   */
  public function usesGroupBy() {
    return FALSE;
  }
  public function query() {
    $this->query
      ->addOrderBy('rand');
  }
  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form, $form_state);
    $form['order']['#access'] = FALSE;
  }

}

Classes

Namesort descending Description
Random Handle a random sort.