function module_config_sort in Drupal 10
Same name and namespace in other branches
- 8 core/includes/module.inc \module_config_sort()
- 9 core/includes/module.inc \module_config_sort()
Sorts the configured list of enabled modules.
The list of enabled modules is expected to be ordered by weight and name. The list is always sorted on write to avoid the overhead on read.
Parameters
array $data: An array of module configuration data.
Return value
array An array of module configuration data sorted by weight and name.
8 calls to module_config_sort()
- ConfigImportUITest::testImport in core/
modules/ config/ tests/ src/ Functional/ ConfigImportUITest.php - Tests importing configuration.
- DrupalFlushAllCachesTest::testDrupalFlushAllCachesModuleList in core/
tests/ Drupal/ KernelTests/ Core/ Common/ DrupalFlushAllCachesTest.php - Tests that drupal_flush_all_caches() uses core.extension properly.
- ExcludedModulesEventSubscriber::onConfigTransformImport in core/
lib/ Drupal/ Core/ EventSubscriber/ ExcludedModulesEventSubscriber.php - Transform the storage which is used to import the configuration.
- InstallerExistingConfigTestBase::prepareEnvironment in core/
tests/ Drupal/ FunctionalTests/ Installer/ InstallerExistingConfigTestBase.php - Prepares the current environment for running the test.
- ModuleInstaller::install in core/
lib/ Drupal/ Core/ Extension/ ModuleInstaller.php
File
- core/
includes/ module.inc, line 108 - API for loading and interacting with Drupal modules.
Code
function module_config_sort($data) {
// PHP array sorting functions such as uasort() do not work with both keys and
// values at the same time, so we achieve weight and name sorting by computing
// strings with both information concatenated (weight first, name second) and
// use that as a regular string sort reference list via array_multisort(),
// compound of "[sign-as-integer][padded-integer-weight][name]"; e.g., given
// two modules and weights (spaces added for clarity):
// - Block with weight -5: 0 0000000000000000005 block
// - Node with weight 0: 1 0000000000000000000 node
$sort = [];
foreach ($data as $name => $weight) {
// Prefix negative weights with 0, positive weights with 1.
// +/- signs cannot be used, since + (ASCII 43) is before - (ASCII 45).
$prefix = (int) ($weight >= 0);
// The maximum weight is PHP_INT_MAX, so pad all weights to 19 digits.
$sort[] = $prefix . sprintf('%019d', abs($weight)) . $name;
}
array_multisort($sort, SORT_STRING, $data);
return $data;
}