function SupportedReleaseValidator::validate
Same name and namespace in other branches
- 11.x core/modules/package_manager/src/Validator/SupportedReleaseValidator.php \Drupal\package_manager\Validator\SupportedReleaseValidator::validate()
Checks that the packages are secure and supported.
Parameters
\Drupal\package_manager\Event\PreApplyEvent $event: The event object.
File
-
core/
modules/ package_manager/ src/ Validator/ SupportedReleaseValidator.php, line 77
Class
- SupportedReleaseValidator
- Validates that updated projects are secure and supported.
Namespace
Drupal\package_manager\ValidatorCode
public function validate(PreApplyEvent $event) : void {
$active = $this->composerInspector
->getInstalledPackagesList($this->pathLocator
->getProjectRoot());
$staged = $this->composerInspector
->getInstalledPackagesList($event->sandboxManager
->getSandboxDirectory());
$updated_packages = array_merge($staged->getPackagesNotIn($active)
->getArrayCopy(), $staged->getPackagesWithDifferentVersionsIn($active)
->getArrayCopy());
$unknown_packages = [];
$unsupported_packages = [];
foreach ($updated_packages as $package_name => $staged_package) {
// Only packages of the types 'drupal-module' or 'drupal-theme' that
// start with 'drupal/' will have update XML from drupal.org.
if (!in_array($staged_package->type, [
'drupal-module',
'drupal-theme',
], TRUE) || !str_starts_with($package_name, 'drupal/')) {
continue;
}
$project_name = $staged[$package_name]->getProjectName();
if (empty($project_name)) {
$unknown_packages[] = $package_name;
continue;
}
$semantic_version = $staged_package->version;
if (!$this->isSupportedRelease($project_name, $semantic_version)) {
$unsupported_packages[] = $this->t('@project_name (@package_name) @version', [
'@project_name' => $project_name,
'@package_name' => $package_name,
'@version' => $semantic_version,
]);
}
}
if ($unsupported_packages) {
$summary = $this->formatPlural(count($unsupported_packages), 'Cannot update because the following project version is not in the list of installable releases.', 'Cannot update because the following project versions are not in the list of installable releases.');
$event->addError($unsupported_packages, $summary);
}
if ($unknown_packages) {
$event->addError([
$this->formatPlural(count($unknown_packages), 'Cannot update because the following new or updated Drupal package does not have project information: @unknown_packages', 'Cannot update because the following new or updated Drupal packages do not have project information: @unknown_packages', [
'@unknown_packages' => implode(', ', $unknown_packages),
]),
]);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.