function ViewsDataHelper::fetchedFieldSort

Same name and namespace in other branches
  1. 8.9.x core/modules/views/src/ViewsDataHelper.php \Drupal\views\ViewsDataHelper::fetchedFieldSort()
  2. 10 core/modules/views/src/ViewsDataHelper.php \Drupal\views\ViewsDataHelper::fetchedFieldSort()
  3. 11.x core/modules/views/src/ViewsDataHelper.php \Drupal\views\ViewsDataHelper::fetchedFieldSort()

Sort function for fetched fields.

Parameters

array $a: First item for comparison. The compared items should be associative arrays that include a 'group' and a 'title' key.

array $b: Second item for comparison.

Return value

int Returns -1 if $a comes before $b, 1 other way round and 0 if it cannot be decided.

File

core/modules/views/src/ViewsDataHelper.php, line 175

Class

ViewsDataHelper
Defines a helper class for stuff related to views data.

Namespace

Drupal\views

Code

protected static function fetchedFieldSort($a, $b) {
    $a_group = mb_strtolower($a['group']);
    $b_group = mb_strtolower($b['group']);
    if ($a_group != $b_group) {
        return $a_group <=> $b_group;
    }
    $a_title = mb_strtolower($a['title']);
    $b_title = mb_strtolower($b['title']);
    return $a_title <=> $b_title;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.