You are here

protected function ProjectCollector::collateExtensionsIntoProjects in Upgrade Status 8.2

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

Finds topmost extension for each extension and keeps only that.

Parameters

\Drupal\Core\Extension\Extension[] $extensions: List of all enabled extensions in a category.

Return value

\Drupal\Core\Extension\Extension[] List of extensions, with only the topmost extension left for each extension that has a parent extension.

1 call to ProjectCollector::collateExtensionsIntoProjects()
ProjectCollector::collectProjects in src/ProjectCollector.php
Collect projects of installed modules grouped by custom and contrib.

File

src/ProjectCollector.php, line 164

Class

ProjectCollector
Collects projects collated for the purposes of upgrade status.

Namespace

Drupal\upgrade_status

Code

protected function collateExtensionsIntoProjects(array $extensions) {
  foreach ($extensions as $name_a => $extension_a) {
    $path_a = $extension_a
      ->getPath() . '/';
    $path_a_length = strlen($path_a);
    foreach ($extensions as $name_b => $extension_b) {

      // Skip collation for test modules except where we test that.
      if (strpos($name_b, 'upgrade_status_test_') === 0 && strpos($name_b, 'upgrade_status_test_submodules_') !== 0) {
        continue;
      }
      $path_b = $extension_b
        ->getPath();

      // If the extension is not the same but the beginning of paths match,
      // remove this extension from the list as it is part of another one.
      if ($name_b != $name_a && substr($path_b, 0, $path_a_length) === $path_a) {
        unset($extensions[$name_b]);
      }
    }
  }
  return $extensions;
}