function ValidationResult::__construct

Creates a ValidationResult object.

Parameters

int $severity: The severity of the result. Should be one of the SystemManager::REQUIREMENT_* constants.

\Drupal\Core\StringTranslation\TranslatableMarkup[]|string[] $messages: The result messages.

\Drupal\Core\StringTranslation\TranslatableMarkup|null $summary: A succinct summary of the result.

bool $assert_translatable: Whether to assert the messages are translatable. Internal use only.

Throws

\InvalidArgumentException Thrown if $messages is empty, or if it has 2 or more items but $summary is NULL.

File

core/modules/package_manager/src/ValidationResult.php, line 36

Class

ValidationResult
A value object to contain the results of a validation.

Namespace

Drupal\package_manager

Code

private function __construct(int $severity, array $messages, ?TranslatableMarkup $summary, bool $assert_translatable) {
    if ($assert_translatable) {
        assert(Inspector::assertAll(fn($message) => $message instanceof TranslatableMarkup, $messages));
    }
    if (empty($messages)) {
        throw new \InvalidArgumentException('At least one message is required.');
    }
    if (count($messages) > 1 && !$summary) {
        throw new \InvalidArgumentException('If more than one message is provided, a summary is required.');
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.