Skip to content
Snippets Groups Projects
Commit 01a9baf8 authored by Adam G-H's avatar Adam G-H
Browse files

Issue #3252533 by phenaproxima, tedbow: Remove the ability for post-operation...

Issue #3252533 by phenaproxima, tedbow: Remove the ability for post-operation stage events to flag warnings
parent 3767acb5
No related branches found
No related tags found
1 merge request!137Issue #3252533: Remove the ability for post-operation stage events to flag warnings
Showing with 9 additions and 103 deletions
<?php
namespace Drupal\package_manager\Event;
use Drupal\Core\StringTranslation\TranslatableMarkup;
/**
* Defines an interface for events which can collect validation errors.
*/
interface ErrorEventInterface {
/**
* Adds a validation error.
*
* @param \Drupal\Core\StringTranslation\TranslatableMarkup[] $messages
* The error messages.
* @param \Drupal\Core\StringTranslation\TranslatableMarkup|null $summary
* (optional) The summary.
*/
public function addError(array $messages, TranslatableMarkup $summary = NULL);
}
......@@ -5,5 +5,5 @@ namespace Drupal\package_manager\Event;
/**
* Event fired after staged changes are synced to the active directory.
*/
class PostApplyEvent extends PostOperationStageEvent {
class PostApplyEvent extends StageEvent {
}
......@@ -5,5 +5,5 @@ namespace Drupal\package_manager\Event;
/**
* Event fired after a staging area has been created.
*/
class PostCreateEvent extends PostOperationStageEvent {
class PostCreateEvent extends StageEvent {
}
......@@ -5,5 +5,5 @@ namespace Drupal\package_manager\Event;
/**
* Event fired after the staging area is destroyed.
*/
class PostDestroyEvent extends PostOperationStageEvent {
class PostDestroyEvent extends StageEvent {
}
<?php
namespace Drupal\package_manager\Event;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\package_manager\ValidationResult;
/**
* Base class for events dispatched after a stage life cycle operation.
*/
abstract class PostOperationStageEvent extends StageEvent implements WarningEventInterface {
/**
* {@inheritdoc}
*/
public function addWarning(array $messages, ?TranslatableMarkup $summary = NULL) {
$this->results[] = ValidationResult::createWarning($messages, $summary);
}
}
......@@ -5,5 +5,5 @@ namespace Drupal\package_manager\Event;
/**
* Event fired after packages are added to the staging area.
*/
class PostRequireEvent extends PostOperationStageEvent {
class PostRequireEvent extends StageEvent {
}
......@@ -8,7 +8,7 @@ use Drupal\package_manager\ValidationResult;
/**
* Base class for events dispatched before a stage life cycle operation.
*/
abstract class PreOperationStageEvent extends StageEvent implements ErrorEventInterface {
abstract class PreOperationStageEvent extends StageEvent {
/**
* {@inheritdoc}
......
<?php
namespace Drupal\package_manager\Event;
use Drupal\Core\StringTranslation\TranslatableMarkup;
/**
* Defines an interface for events which can collect validation warnings.
*/
interface WarningEventInterface {
/**
* Adds a warning.
*
* @param array $messages
* The warning messages.
* @param \Drupal\Core\StringTranslation\TranslatableMarkup|null $summary
* (optional) The summary.
*/
public function addWarning(array $messages, TranslatableMarkup $summary = NULL);
}
<?php
namespace Drupal\package_manager\EventSubscriber;
use Drupal\package_manager\Event\PostOperationStageEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Defines an interface for classes that validate a stage after an operation.
*/
interface PostOperationStageValidatorInterface extends EventSubscriberInterface {
/**
* Validates a stage after an operation.
*
* @param \Drupal\package_manager\Event\PostOperationStageEvent $event
* The stage event.
*/
public function validateStagePostOperation(PostOperationStageEvent $event): void;
}
......@@ -2,7 +2,6 @@
namespace Drupal\Tests\package_manager\Kernel;
use Drupal\package_manager\Event\ErrorEventInterface;
use Drupal\package_manager\Event\PostApplyEvent;
use Drupal\package_manager\Event\PostCreateEvent;
use Drupal\package_manager\Event\PostDestroyEvent;
......@@ -10,9 +9,9 @@ use Drupal\package_manager\Event\PostRequireEvent;
use Drupal\package_manager\Event\PreApplyEvent;
use Drupal\package_manager\Event\PreCreateEvent;
use Drupal\package_manager\Event\PreDestroyEvent;
use Drupal\package_manager\Event\PreOperationStageEvent;
use Drupal\package_manager\Event\PreRequireEvent;
use Drupal\package_manager\Event\StageEvent;
use Drupal\package_manager\Event\WarningEventInterface;
use Drupal\package_manager\Exception\StageValidationException;
use Drupal\package_manager\Stage;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
......@@ -76,7 +75,7 @@ class StageEventsTest extends PackageManagerKernelTestBase implements EventSubsc
/**
* Handles a staging area life cycle event.
*
* @param \Drupal\package_manager\Event\PreOperationStageEvent|\Drupal\package_manager\Event\PostOperationStageEvent $event
* @param \Drupal\package_manager\Event\StageEvent $event
* The event object.
*/
public function handleEvent(StageEvent $event): void {
......@@ -118,13 +117,9 @@ class StageEventsTest extends PackageManagerKernelTestBase implements EventSubsc
public function providerValidationResults(): array {
return [
[PreCreateEvent::class],
[PostCreateEvent::class],
[PreRequireEvent::class],
[PostRequireEvent::class],
[PreApplyEvent::class],
[PostApplyEvent::class],
[PreDestroyEvent::class],
[PostDestroyEvent::class],
];
}
......@@ -141,12 +136,9 @@ class StageEventsTest extends PackageManagerKernelTestBase implements EventSubsc
// class under test.
$handler = function (StageEvent $event) use ($event_class): void {
if (get_class($event) === $event_class) {
if ($event instanceof ErrorEventInterface) {
if ($event instanceof PreOperationStageEvent) {
$event->addError([['Burn, baby, burn']]);
}
elseif ($event instanceof WarningEventInterface) {
$event->addWarning(['Be careful about fires.']);
}
}
};
$this->container->get('event_dispatcher')
......
......@@ -5,7 +5,6 @@ namespace Drupal\automatic_updates\Event;
use Drupal\automatic_updates\Updater;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\package_manager\Event\PreOperationStageEvent;
use Drupal\package_manager\Event\WarningEventInterface;
use Drupal\package_manager\ValidationResult;
/**
......@@ -20,7 +19,7 @@ use Drupal\package_manager\ValidationResult;
*
* @see \Drupal\automatic_updates\Validation\ReadinessValidationManager
*/
class ReadinessCheckEvent extends PreOperationStageEvent implements WarningEventInterface {
class ReadinessCheckEvent extends PreOperationStageEvent {
/**
* The desired package versions to update to, keyed by package name.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment