You are here

private function ProfileEntitySortable::orderByFields in Open Social 10.2.x

Same name and namespace in other branches
  1. 10.3.x modules/social_features/social_profile/src/Plugin/views/field/ProfileEntitySortable.php \Drupal\social_profile\Plugin\views\field\ProfileEntitySortable::orderByFields()

Get the list of fields that will be used for sorting.

Return value

string[] List of fields.

1 call to ProfileEntitySortable::orderByFields()
ProfileEntitySortable::clickSort in modules/social_features/social_profile/src/Plugin/views/field/ProfileEntitySortable.php
Adds an ORDER BY clause to the query for click sort columns.

File

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

Class

ProfileEntitySortable
Field handler to sort rendered profile entity in views.

Namespace

Drupal\social_profile\Plugin\views\field

Code

private function orderByFields() : array {

  // Set default sort fields.
  $fields = [
    'profile_name',
  ];

  // If social_profile_privacy module is not enabled then we sort users by
  // default sort field.
  if (!$this->moduleHandler
    ->moduleExists('social_profile_privacy')) {
    return $fields;
  }

  // If the user has no access to view hidden fields then we sort users by
  // default sort fields.
  if (!$this->currentUser
    ->hasPermission('social profile privacy view hidden fields')) {
    return $fields;
  }

  // In the case where the user has access to view hidden fields, we need to
  // sort profiles by Firstname and Lastname.
  $fields = [
    'field_profile_first_name',
    'field_profile_last_name',
  ];

  // If module social_profile_fields is enabled then also need to sort
  // profiles by Nickname.
  if ($this->moduleHandler
    ->moduleExists('social_profile_fields')) {
    $fields[] = 'field_profile_nick_name';
  }
  return $fields;
}