You are here

public function ProfileEntitySortable::clickSort in Open Social 10.1.x

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_profile/src/Plugin/views/field/ProfileEntitySortable.php \Drupal\social_profile\Plugin\views\field\ProfileEntitySortable::clickSort()
  2. 10.3.x modules/social_features/social_profile/src/Plugin/views/field/ProfileEntitySortable.php \Drupal\social_profile\Plugin\views\field\ProfileEntitySortable::clickSort()
  3. 10.0.x modules/social_features/social_profile/src/Plugin/views/field/ProfileEntitySortable.php \Drupal\social_profile\Plugin\views\field\ProfileEntitySortable::clickSort()
  4. 10.2.x modules/social_features/social_profile/src/Plugin/views/field/ProfileEntitySortable.php \Drupal\social_profile\Plugin\views\field\ProfileEntitySortable::clickSort()

Adds an ORDER BY clause to the query for click sort columns.

Parameters

string $order: Either ASC or DESC

Overrides FieldPluginBase::clickSort

File

modules/social_features/social_profile/src/Plugin/views/field/ProfileEntitySortable.php, line 19

Class

ProfileEntitySortable
Field handler to sort rendered profile entity in views.

Namespace

Drupal\social_profile\Plugin\views\field

Code

public function clickSort($order) {
  if (isset($this->field_alias)) {

    // If we want to sort on the profile name, add the correct alias.
    if ($this->table === 'profile' && $this->field === 'profile_entity_sortable') {
      $this->field_alias = $this->view->relationship['profile']->tableAlias . '.name';
    }

    // Since fields should always have themselves already added, just
    // add a sort on the field.
    $params = $this->options['group_type'] != 'group' ? [
      'function' => $this->options['group_type'],
    ] : [];
    $this->query
      ->addOrderBy(NULL, NULL, $order, $this->field_alias, $params);
  }
}