diff --git a/package_manager/package_manager.services.yml b/package_manager/package_manager.services.yml index 3fa0bfa707d037d81d7bba4669f243fd53cd2bfd..61febebe74e97f5d32000dc4f9e38d38b201c5cf 100644 --- a/package_manager/package_manager.services.yml +++ b/package_manager/package_manager.services.yml @@ -128,6 +128,12 @@ services: - '@string_translation' tags: - { name: event_subscriber } + package_manager.test_site_excluder: + class: Drupal\package_manager\EventSubscriber\TestSiteExcluder + arguments: + - '@package_manager.path_locator' + tags: + - { name: event_subscriber } package_manager.excluded_paths_subscriber: class: Drupal\package_manager\EventSubscriber\ExcludedPathsSubscriber arguments: diff --git a/package_manager/src/EventSubscriber/ExcludedPathsSubscriber.php b/package_manager/src/EventSubscriber/ExcludedPathsSubscriber.php index 844105463c3ddbe431c7e931d562216874cc1043..99d649794e17683880de48eb4e6006a2eaf6667e 100644 --- a/package_manager/src/EventSubscriber/ExcludedPathsSubscriber.php +++ b/package_manager/src/EventSubscriber/ExcludedPathsSubscriber.php @@ -83,10 +83,6 @@ class ExcludedPathsSubscriber implements EventSubscriberInterface { // project root, and paths that are relative to the web root. $web = $project = []; - // Always ignore automated test directories. If they exist, they will be in - // the web root. - $web[] = 'sites/simpletest'; - // If the core-vendor-hardening plugin (used in the legacy-project template) // is present, it may have written security hardening files in the vendor // directory. They should always be ignored. diff --git a/package_manager/src/EventSubscriber/TestSiteExcluder.php b/package_manager/src/EventSubscriber/TestSiteExcluder.php new file mode 100644 index 0000000000000000000000000000000000000000..8c2ea94b7a44a62fe902ea0a7f118d3c491092c9 --- /dev/null +++ b/package_manager/src/EventSubscriber/TestSiteExcluder.php @@ -0,0 +1,50 @@ +<?php + +namespace Drupal\package_manager\EventSubscriber; + +use Drupal\package_manager\Event\PreApplyEvent; +use Drupal\package_manager\Event\PreCreateEvent; +use Drupal\package_manager\Event\StageEvent; +use Drupal\package_manager\PathLocator; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; + +/** + * Excludes 'sites/simpletest' from staging operations. + */ +class TestSiteExcluder implements EventSubscriberInterface { + + use PathExclusionsTrait; + + /** + * Constructs a TestSiteExcluder object. + * + * @param \Drupal\package_manager\PathLocator $path_locator + * The path locator service. + */ + public function __construct(PathLocator $path_locator) { + $this->pathLocator = $path_locator; + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() { + return [ + PreCreateEvent::class => 'excludeTestSites', + PreApplyEvent::class => 'excludeTestSites', + ]; + } + + /** + * Excludes sites/simpletest from staging operations. + * + * @param \Drupal\package_manager\Event\StageEvent $event + * The event object. + */ + public function excludeTestSites(StageEvent $event): void { + // Always ignore automated test directories. If they exist, they will be in + // the web root. + $this->excludeInWebRoot($event, ['sites/simpletest']); + } + +}