You are here

class Sort in JSON:API 8

Same name and namespace in other branches
  1. 8.2 src/Query/Sort.php \Drupal\jsonapi\Query\Sort

Gathers information about the sort parameter.

@internal

Hierarchy

  • class \Drupal\jsonapi\Query\Sort

Expanded class hierarchy of Sort

6 files declare their use of Sort
EntityResource.php in src/Controller/EntityResource.php
EntityResourceTest.php in tests/src/Kernel/Controller/EntityResourceTest.php
JsonApiParamEnhancer.php in src/Routing/JsonApiParamEnhancer.php
JsonApiParamEnhancerTest.php in tests/src/Unit/Routing/JsonApiParamEnhancerTest.php
SortNormalizer.php in src/Normalizer/SortNormalizer.php

... See full list

File

src/Query/Sort.php, line 10

Namespace

Drupal\jsonapi\Query
View source
class Sort {

  /**
   * The JSON API sort key name.
   *
   * @var string
   */
  const KEY_NAME = 'sort';

  /**
   * The field key in the sort parameter: sort[lorem][<field>].
   *
   * @var string
   */
  const PATH_KEY = 'path';

  /**
   * The direction key in the sort parameter: sort[lorem][<direction>].
   *
   * @var string
   */
  const DIRECTION_KEY = 'direction';

  /**
   * The langcode key in the sort parameter: sort[lorem][<langcode>].
   *
   * @var string
   */
  const LANGUAGE_KEY = 'langcode';

  /**
   * The fields on which to sort.
   *
   * @var string
   */
  protected $fields;

  /**
   * Constructs a new Sort object.
   *
   * Takes an array of sort fields. Example:
   *   [
   *     [
   *       'path' => 'changed',
   *       'direction' => 'DESC',
   *     ],
   *     [
   *       'path' => 'title',
   *       'direction' => 'ASC',
   *       'langcode' => 'en-US',
   *     ],
   *   ]
   *
   * @param array $fields
   *   The the entity query sort fields.
   */
  public function __construct(array $fields) {
    $this->fields = $fields;
  }

  /**
   * Gets the root condition group.
   */
  public function fields() {
    return $this->fields;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Sort::$fields protected property The fields on which to sort.
Sort::DIRECTION_KEY constant The direction key in the sort parameter: sort[lorem][<direction>].
Sort::fields public function Gets the root condition group.
Sort::KEY_NAME constant The JSON API sort key name.
Sort::LANGUAGE_KEY constant The langcode key in the sort parameter: sort[lorem][<langcode>].
Sort::PATH_KEY constant The field key in the sort parameter: sort[lorem][<field>].
Sort::__construct public function Constructs a new Sort object.