You are here

public function UnusedModulesHelperService::getModulesByProject in Unused Modules 8

Returns an array with all available modules.

Return value

\Drupal\unused_modules\UnusedModulesExtensionDecorator[]

File

src/UnusedModulesHelperService.php, line 18

Class

UnusedModulesHelperService
Common Unused Modules functionality.

Namespace

Drupal\unused_modules

Code

public function getModulesByProject() {
  $enabled_modules = static::getEnabledModules();
  $available_modules = static::getAvailableModules();

  // Projects are organized by path.
  // Foreach path check if there are $enabled_modules.
  // If so, project_has_enabled_modules = TRUE.
  foreach ($available_modules as &$available_module) {
    foreach ($enabled_modules as $enabled_module) {
      if (isset($enabled_module)) {

        // Test if there is an enabled module with the same path.
        if ($enabled_module->projectPath === $available_module->projectPath) {
          $available_module->projectHasEnabledModules = TRUE;
        }

        // Test if module is enabled.
        if ($enabled_module
          ->getPathname() === $available_module
          ->getPathname()) {
          $available_module->moduleIsEnabled = TRUE;
        }
      }
    }
  }

  // Sort by project.
  uasort($available_modules, [
    $this,
    'sortByProject',
  ]);
  return $available_modules;
}