Random.php

Same filename in this branch
  1. 9 core/lib/Drupal/Component/Utility/Random.php
Same filename in other branches
  1. 8.9.x core/modules/views/src/Plugin/views/sort/Random.php
  2. 8.9.x core/lib/Drupal/Component/Utility/Random.php
  3. 10 core/modules/views/src/Plugin/views/sort/Random.php
  4. 10 core/tests/Drupal/TestTools/Random.php
  5. 10 core/lib/Drupal/Component/Utility/Random.php
  6. 11.x core/modules/views/src/Plugin/views/sort/Random.php
  7. 11.x core/tests/Drupal/TestTools/Random.php
  8. 11.x core/lib/Drupal/Component/Utility/Random.php

Namespace

Drupal\views\Plugin\views\sort

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

Title Deprecated Summary
Random Handle a random sort.

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