You are here

public function AllowedPackages::getAllowedPackages in Drupal 9

Same name and namespace in other branches
  1. 8 composer/Plugin/Scaffold/AllowedPackages.php \Drupal\Composer\Plugin\Scaffold\AllowedPackages::getAllowedPackages()

Gets a list of all packages that are allowed to copy scaffold files.

We will implicitly allow the projects 'drupal/legacy-scaffold-assets' and 'drupal/core' to scaffold files, if they are present. Any other project must be explicitly whitelisted in the top-level composer.json file in order to be allowed to override scaffold files. Configuration for packages specified later will override configuration specified by packages listed earlier. In other words, the last listed package has the highest priority. The root package will always be returned at the end of the list.

Return value

\Composer\Package\PackageInterface[] An array of allowed Composer packages.

File

composer/Plugin/Scaffold/AllowedPackages.php, line 80

Class

AllowedPackages
Determine recursively which packages have been allowed to scaffold files.

Namespace

Drupal\Composer\Plugin\Scaffold

Code

public function getAllowedPackages() {
  $top_level_packages = $this
    ->getTopLevelAllowedPackages();
  $allowed_packages = $this
    ->recursiveGetAllowedPackages($top_level_packages);

  // If the root package defines any file mappings, then implicitly add it
  // to the list of allowed packages. Add it at the end so that it overrides
  // all the preceding packages.
  if ($this->manageOptions
    ->getOptions()
    ->hasFileMapping()) {
    $root_package = $this->composer
      ->getPackage();
    unset($allowed_packages[$root_package
      ->getName()]);
    $allowed_packages[$root_package
      ->getName()] = $root_package;
  }

  // Handle any newly-added packages that are not already allowed.
  return $this
    ->evaluateNewPackages($allowed_packages);
}