class EnabledExtensionsValidator
Validates no enabled Drupal extensions are removed from the stage directory.
@internal This is an internal part of Package Manager and may be changed or removed at any time without warning. External code should not interact with this class.
Hierarchy
- class \Drupal\package_manager\Validator\EnabledExtensionsValidator implements \Symfony\Component\EventDispatcher\EventSubscriberInterface uses \Drupal\Core\StringTranslation\StringTranslationTrait
Expanded class hierarchy of EnabledExtensionsValidator
File
-
core/
modules/ package_manager/ src/ Validator/ EnabledExtensionsValidator.php, line 23
Namespace
Drupal\package_manager\ValidatorView source
final class EnabledExtensionsValidator implements EventSubscriberInterface {
use StringTranslationTrait;
public function __construct(PathLocator $pathLocator, ModuleHandlerInterface $moduleHandler, ComposerInspector $composerInspector, ThemeHandlerInterface $themeHandler) {
}
/**
* Validates that no enabled Drupal extensions have been removed.
*
* @param \Drupal\package_manager\Event\PreApplyEvent $event
* The event object.
*/
public function validate(PreApplyEvent $event) : void {
$active_packages_list = $this->composerInspector
->getInstalledPackagesList($this->pathLocator
->getProjectRoot());
$stage_packages_list = $this->composerInspector
->getInstalledPackagesList($event->stage
->getStageDirectory());
$extensions_list = $this->moduleHandler
->getModuleList() + $this->themeHandler
->listInfo();
foreach ($extensions_list as $extension) {
$extension_name = $extension->getName();
$package = $active_packages_list->getPackageByDrupalProjectName($extension_name);
if ($package && $stage_packages_list->getPackageByDrupalProjectName($extension_name) === NULL) {
$removed_project_messages[] = t("'@name' @type (provided by <code>@package</code>)", [
'@name' => $extension_name,
'@type' => $extension->getType(),
'@package' => $package->name,
]);
}
}
if (!empty($removed_project_messages)) {
$removed_packages_summary = $this->formatPlural(count($removed_project_messages), 'The update cannot proceed because the following enabled Drupal extension was removed during the update.', 'The update cannot proceed because the following enabled Drupal extensions were removed during the update.');
$event->addError($removed_project_messages, $removed_packages_summary);
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() : array {
return [
PreApplyEvent::class => 'validate',
];
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overrides |
---|---|---|---|---|
EnabledExtensionsValidator::getSubscribedEvents | public static | function | ||
EnabledExtensionsValidator::validate | public | function | Validates that no enabled Drupal extensions have been removed. | |
EnabledExtensionsValidator::__construct | public | function | ||
StringTranslationTrait::$stringTranslation | protected | property | The string translation service. | 3 |
StringTranslationTrait::formatPlural | protected | function | Formats a string containing a count of items. | |
StringTranslationTrait::getNumberOfPlurals | protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait::getStringTranslation | protected | function | Gets the string translation service. | |
StringTranslationTrait::setStringTranslation | public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait::t | protected | function | Translates a string to the current language or to a given language. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.