You are here

public function PackageManager::getExtensionPackages in Composer Manager 8

Returns the extension packages.

The composer.json file of each extension (module, profile) under each site is loaded and returned.

Return value

array An array of packages, keyed by the providing Drupal extension name.

Overrides PackageManagerInterface::getExtensionPackages

See also

\Drupal\Core\Extension\ExtensionDiscovery

3 calls to PackageManager::getExtensionPackages()
PackageManager::buildMergedExtensionPackage in src/PackageManager.php
Builds a package containing the merged fields of all extension packages.
PackageManager::processRequiredPackages in src/PackageManager.php
Formats and sorts the provided list of packages.
PackageManager::rebuildRootPackage in src/PackageManager.php
Rebuilds the root package by merging in the extension requirements.

File

src/PackageManager.php, line 48

Class

PackageManager
Manages composer packages.

Namespace

Drupal\composer_manager

Code

public function getExtensionPackages() {
  if (!isset($this->packages['extension'])) {
    $listing = new ExtensionDiscovery($this->root);

    // Get all profiles, and modules belonging to those profiles.
    // @todo Scan themes as well?
    $profiles = $listing
      ->scan('profile');
    $profile_directories = array_map(function ($profile) {
      return $profile
        ->getPath();
    }, $profiles);
    $listing
      ->setProfileDirectories($profile_directories);
    $modules = $listing
      ->scan('module');
    $extensions = $profiles + $modules;
    $installed_packages = $this
      ->getInstalledPackages();
    $installed_packages = array_map(function ($package) {
      return $package['name'];
    }, $installed_packages);
    $this->packages['extension'] = [];
    foreach ($extensions as $extension_name => $extension) {
      $filename = $this->root . '/' . $extension
        ->getPath() . '/composer.json';
      if (is_readable($filename)) {
        $extension_package = JsonFile::read($filename);

        // The package must at least have a name and some requirements.
        if (empty($extension_package['name'])) {
          continue;
        }
        if (empty($extension_package['require']) && empty($extension_package['require-dev'])) {
          continue;
        }
        if (in_array($extension_package['name'], $installed_packages)) {

          // This extension is already managed with Composer.
          continue;
        }

        // The path is required by rebuildRootPackage().
        $extension_package['extra']['path'] = $extension
          ->getPath() . '/composer.json';
        $this->packages['extension'][$extension_name] = $extension_package;
      }
    }
  }
  return $this->packages['extension'];
}