You are here

protected function PluginHelperTrait::getSortedDefinitions in Layout Builder Restrictions 8.2

Sort block categories alphabetically.

Parameters

array $definitions: The block definitions, with category values.

string $label_key: The module name, if no category value is present on the block.

Return value

array The alphabetically sorted categories with definitions.

1 call to PluginHelperTrait::getSortedDefinitions()
PluginHelperTrait::getGroupedDefinitions in src/Traits/PluginHelperTrait.php
Method to categorize blocks in a multilingual-friendly way.

File

src/Traits/PluginHelperTrait.php, line 207

Class

PluginHelperTrait
Methods to help Layout Builder Restrictions plugins.

Namespace

Drupal\layout_builder_restrictions\Traits

Code

protected function getSortedDefinitions(array $definitions = NULL, $label_key = 'label') {
  uasort($definitions, function ($a, $b) use ($label_key) {
    if ($a['category'] != $b['category']) {
      return strnatcasecmp($a['category'], $b['category']);
    }
    return strnatcasecmp($a[$label_key], $b[$label_key]);
  });
  return $definitions;
}