Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x

Random.php

Same filename in this branch
  1. 11.1.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;
use Drupal\views\Attribute\ViewsSort;

/**
 * Handle a random sort.
 */
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.

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal