class PreOperationStageEvent
Base class for events dispatched before a stage life cycle operation.
Hierarchy
- class \Drupal\package_manager\Event\StageEvent extends \Symfony\Contracts\EventDispatcher\Event
- class \Drupal\package_manager\Event\PreOperationStageEvent extends \Drupal\package_manager\Event\StageEvent
Expanded class hierarchy of PreOperationStageEvent
23 files declare their use of PreOperationStageEvent
- AllowedScaffoldPackagesValidator.php in core/
modules/ package_manager/ src/ Validator/ AllowedScaffoldPackagesValidator.php - BaseRequirementsFulfilledValidator.php in core/
modules/ package_manager/ src/ Validator/ BaseRequirementsFulfilledValidator.php - BaseRequirementsFulfilledValidatorTest.php in core/
modules/ package_manager/ tests/ src/ Kernel/ BaseRequirementsFulfilledValidatorTest.php - BaseRequirementValidatorTrait.php in core/
modules/ package_manager/ src/ Validator/ BaseRequirementValidatorTrait.php - ComposerPatchesValidator.php in core/
modules/ package_manager/ src/ Validator/ ComposerPatchesValidator.php
File
-
core/
modules/ package_manager/ src/ Event/ PreOperationStageEvent.php, line 14
Namespace
Drupal\package_manager\EventView source
abstract class PreOperationStageEvent extends StageEvent {
/**
* The validation results.
*
* @var \Drupal\package_manager\ValidationResult[]
*/
protected $results = [];
/**
* Gets the validation results.
*
* @param int|null $severity
* (optional) The severity for the results to return. Should be one of the
* SystemManager::REQUIREMENT_* constants.
*
* @return \Drupal\package_manager\ValidationResult[]
* The validation results.
*/
public function getResults(?int $severity = NULL) : array {
if ($severity !== NULL) {
return array_filter($this->results, function ($result) use ($severity) {
return $result->severity === $severity;
});
}
return $this->results;
}
/**
* Convenience method to flag a validation error.
*
* @param \Drupal\Core\StringTranslation\TranslatableMarkup[] $messages
* The error messages.
* @param \Drupal\Core\StringTranslation\TranslatableMarkup|null $summary
* The summary of error messages. Must be passed if there is more than one
* message.
*/
public function addError(array $messages, ?TranslatableMarkup $summary = NULL) : void {
$this->addResult(ValidationResult::createError(array_values($messages), $summary));
}
/**
* Convenience method, adds an error validation result from a throwable.
*
* @param \Throwable $throwable
* The throwable.
* @param \Drupal\Core\StringTranslation\TranslatableMarkup|null $summary
* (optional) The summary of error messages.
*/
public function addErrorFromThrowable(\Throwable $throwable, ?TranslatableMarkup $summary = NULL) : void {
$this->addResult(ValidationResult::createErrorFromThrowable($throwable, $summary));
}
/**
* Adds a validation result to the event.
*
* @param \Drupal\package_manager\ValidationResult $result
* The validation result to add.
*
* @throws \InvalidArgumentException
* Thrown if the validation result is not an error.
*/
public function addResult(ValidationResult $result) : void {
// Only errors are allowed for this event.
if ($result->severity !== SystemManager::REQUIREMENT_ERROR) {
throw new \InvalidArgumentException('Only errors are allowed.');
}
$this->results[] = $result;
}
/**
* {@inheritdoc}
*/
public function stopPropagation() : void {
if (empty($this->getResults(SystemManager::REQUIREMENT_ERROR))) {
$this->addErrorFromThrowable(new \LogicException('Event propagation stopped without any errors added to the event. This bypasses the package_manager validation system.'));
}
parent::stopPropagation();
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overrides |
---|---|---|---|---|
PreOperationStageEvent::$results | protected | property | The validation results. | |
PreOperationStageEvent::addError | public | function | Convenience method to flag a validation error. | |
PreOperationStageEvent::addErrorFromThrowable | public | function | Convenience method, adds an error validation result from a throwable. | |
PreOperationStageEvent::addResult | public | function | Adds a validation result to the event. | 1 |
PreOperationStageEvent::getResults | public | function | Gets the validation results. | |
PreOperationStageEvent::stopPropagation | public | function | ||
StageEvent::__construct | public | function | Constructs a StageEvent object. | 4 |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.