You are here

public function ProjectCollector::collectProjects in Upgrade Status 8

Same name and namespace in other branches
  1. 8.3 src/ProjectCollector.php \Drupal\upgrade_status\ProjectCollector::collectProjects()
  2. 8.2 src/ProjectCollector.php \Drupal\upgrade_status\ProjectCollector::collectProjects()

Collect projects of installed modules grouped by custom and contrib.

Return value

array An array keyed by 'custom' and 'contrib' where each array is a list of projects grouped into that project group. Custom modules get a project name based on their topmost parent custom module and only that topmost custom module gets included in the list. Each item is a \Drupal\Core\Extension\Extension object in both arrays.

Overrides ProjectCollectorInterface::collectProjects

File

src/ProjectCollector.php, line 73

Class

ProjectCollector
Collects projects collated for the purposes of upgrade status.

Namespace

Drupal\upgrade_status

Code

public function collectProjects() {
  $projects = [
    'custom' => [],
    'contrib' => [],
  ];
  $modules = $this->moduleExtensionList
    ->reset()
    ->getList();
  $themes = $this->themeHandler
    ->rebuildThemeData();
  $profiles = $this->profileExtensionList
    ->getList();
  $extensions = array_merge($modules, $themes, $profiles);
  unset($modules, $themes, $profiles);

  /** @var \Drupal\Core\Extension\Extension $extension */
  foreach ($extensions as $key => $extension) {
    if ($extension->origin === 'core') {

      // Ignore core extensions for the sake of upgrade status.
      continue;
    }
    if ($extension
      ->getType() !== 'profile' && $extension->status === 0) {

      // Ignore disabled extensions.
      continue;
    }

    // If the project is already specified in this extension, use that.
    $project = isset($extension->info['project']) ? $extension->info['project'] : '';
    if (array_key_exists($project, $projects['custom']) || array_key_exists($project, $projects['contrib'])) {

      // If we already have a representative of this project in the list,
      // don't add this extension.
      // @todo Make sure to use the extension with the shortest file path.
      continue;
    }

    // For extensions that are not in core and no project was specified,
    // they are assumed to be custom code. Drupal.org packages contrib
    // extensions with a project key and composer packages also include it.
    if (empty($project)) {
      $projects['custom'][$key] = $extension;
      continue;
    }
    if ($project === 'drupal') {

      // Ensure to omit all core related extension from the list.
      continue;
    }

    // @todo should this use $project as the key?
    $projects['contrib'][$key] = $extension;
  }

  // Collate custom extensions to projects, removing sub-extensions.
  $projects['custom'] = $this
    ->collateCustomExtensionsIntoProjects($projects['custom']);
  return $projects;
}