function AllowedScaffoldPackagesValidator::validate
Validates that only the implicitly allowed packages can use scaffolding.
File
-
core/
modules/ package_manager/ src/ Validator/ AllowedScaffoldPackagesValidator.php, line 37
Class
- AllowedScaffoldPackagesValidator
- Validates the list of packages that are allowed to scaffold files.
Namespace
Drupal\package_manager\ValidatorCode
public function validate(PreOperationStageEvent $event) : void {
$stage = $event->stage;
$path = $event instanceof PreApplyEvent ? $stage->getStageDirectory() : $this->pathLocator
->getProjectRoot();
// @see https://www.drupal.org/docs/develop/using-composer/using-drupals-composer-scaffold
$implicitly_allowed_packages = [
"drupal/legacy-scaffold-assets",
"drupal/core",
];
$extra = Json::decode($this->composerInspector
->getConfig('extra', $path . '/composer.json'));
$allowed_packages = $extra['drupal-scaffold']['allowed-packages'] ?? [];
$extra_packages = array_diff($allowed_packages, $implicitly_allowed_packages);
if (!empty($extra_packages)) {
$event->addError(array_map($this->t(...), $extra_packages), $this->t('Any packages other than the implicitly allowed packages are not allowed to scaffold files. See <a href=":url">the scaffold documentation</a> for more information.', [
':url' => 'https://www.drupal.org/docs/develop/using-composer/using-drupals-composer-scaffold',
]));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.