ModulesWeight.php in Modules weight 8
File
src/ModulesWeight.php
View source
<?php
namespace Drupal\modules_weight;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Extension\ModuleExtensionList;
class ModulesWeight implements ModulesWeightInterface {
protected $configFactory;
protected $moduleExtensionList;
public function __construct(ConfigFactoryInterface $config_factory, ModuleExtensionList $module_extension_list) {
$this->configFactory = $config_factory;
$this->moduleExtensionList = $module_extension_list;
}
public function getModulesList($show_core_modules = FALSE) {
$modules = [];
$installed_modules = $this->moduleExtensionList
->getAllInstalledInfo();
$modules_weight = $this->configFactory
->get('core.extension')
->get('module');
foreach ($installed_modules as $filename => $module_info) {
if (!isset($module_info['hidden']) && ($show_core_modules || $module_info['package'] != 'Core')) {
$modules[$filename]['name'] = $module_info['name'];
$modules[$filename]['description'] = $module_info['description'];
$modules[$filename]['weight'] = $modules_weight[$filename];
$modules[$filename]['package'] = $module_info['package'];
}
}
uasort($modules, [
'Drupal\\modules_weight\\Utility\\SortArray',
'sortByWeightAndName',
]);
return $modules;
}
}