You are here

trait ConfigSelectorSortTrait in Configuration selector 8

Same name and namespace in other branches
  1. 8.2 src/ConfigSelectorSortTrait.php \Drupal\config_selector\ConfigSelectorSortTrait

Provides a sort function for sorting config entities for config_selector.

Hierarchy

2 files declare their use of ConfigSelectorSortTrait
FeatureManageForm.php in src/Form/FeatureManageForm.php
Switcher.php in src/Controller/Switcher.php

File

src/ConfigSelectorSortTrait.php, line 8

Namespace

Drupal\config_selector
View source
trait ConfigSelectorSortTrait {

  /**
   * Sorts an array of configuration entities by priority then config name.
   *
   * @param \Drupal\Core\Config\Entity\ConfigEntityInterface[] $configs
   *   Array of configuration entities to sort.
   *
   * @return \Drupal\Core\Config\Entity\ConfigEntityInterface[]
   *   The sorted array of configuration entities.
   */
  protected function sortConfigEntities(array $configs) {
    uksort($configs, function ($a, $b) use ($configs) {
      $a_priority = $configs[$a]
        ->getThirdPartySetting('config_selector', 'priority', 0);
      $b_priority = $configs[$b]
        ->getThirdPartySetting('config_selector', 'priority', 0);
      if ($a_priority === $b_priority) {
        return strcmp($a, $b);
      }
      return $a_priority < $b_priority ? -1 : 1;
    });
    return $configs;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigSelectorSortTrait::sortConfigEntities protected function Sorts an array of configuration entities by priority then config name.