You are here

class SortsField in Search API sorts 8

A value object for a sorts field.

Hierarchy

Expanded class hierarchy of SortsField

2 files declare their use of SortsField
search_api_sorts_test_hook.module in tests/search_api_sorts_test_hook/search_api_sorts_test_hook.module
Tests all the hooks.
SortsFieldTest.php in tests/src/Unit/SortsFieldTest.php

File

src/SortsField.php, line 8

Namespace

Drupal\search_api_sorts
View source
class SortsField {

  /**
   * The field of the sorting.
   *
   * @var string $field
   */
  protected $field;

  /**
   * The direction of the sorting.
   *
   * @var string $order
   */
  protected $order;

  /**
   * Constructs an instance of the value object.
   *
   * @param string $field
   *   The field to sort on.
   * @param string $order
   *   The direction to sort on.
   */
  public function __construct($field, $order = NULL) {
    $this
      ->setFieldName($field);
    $this
      ->setOrder($order);
  }

  /**
   * Overrides the field to sort on.
   *
   * @param string $field
   *   The field of sorting.
   */
  public function setFieldName($field) {
    $this->field = $field;
  }

  /**
   * Returns the field to sort on.
   *
   * @return string
   *   The field of sorting.
   */
  public function getFieldName() {
    return $this->field;
  }

  /**
   * Overrides the order to sort on.
   *
   * @param string $order
   *   The direction of the sorting.
   */
  public function setOrder($order) {
    $this->order = $order == 'desc' ? 'desc' : 'asc';
  }

  /**
   * Returns the direction of sorting, asc or desc.
   *
   * @return string
   *   The direction of the sorting.
   */
  public function getOrder() {
    return $this->order;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SortsField::$field protected property The field of the sorting.
SortsField::$order protected property The direction of the sorting.
SortsField::getFieldName public function Returns the field to sort on.
SortsField::getOrder public function Returns the direction of sorting, asc or desc.
SortsField::setFieldName public function Overrides the field to sort on.
SortsField::setOrder public function Overrides the order to sort on.
SortsField::__construct public function Constructs an instance of the value object.