Skip to content

Commit

Permalink
Added previous exception arg. into ContentFieldValidationException ctor
Browse files Browse the repository at this point in the history
  • Loading branch information
alongosz committed Jun 27, 2024
1 parent a46adbc commit 181f454
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/lib/Base/Exceptions/ContentFieldValidationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Ibexa\Contracts\Core\Repository\Exceptions\ContentFieldValidationException as APIContentFieldValidationException;
use Ibexa\Core\Base\Translatable;
use Ibexa\Core\Base\TranslatableBase;
use Throwable;

/**
* This Exception is thrown on create or update content one or more given fields are not valid.
Expand Down Expand Up @@ -42,27 +43,27 @@ class ContentFieldValidationException extends APIContentFieldValidationException
*
* @param array<int, array<string, \Ibexa\Contracts\Core\FieldType\ValidationError|\Ibexa\Contracts\Core\FieldType\ValidationError[]>> $errors
*/
public function __construct(array $errors)
public function __construct(array $errors, ?Throwable $previous = null)
{
$this->errors = $errors;
$this->setMessageTemplate('Content fields did not validate');
parent::__construct($this->getBaseTranslation());
parent::__construct($this->getBaseTranslation(), 0, $previous);
}

/**
* Generates: Content fields did not validate exception with additional information on affected fields.
*
* @param array<int, array<string, \Ibexa\Contracts\Core\FieldType\ValidationError|\Ibexa\Contracts\Core\FieldType\ValidationError[]>> $errors
*/
public static function createNewWithMultiline(array $errors, ?string $contentName = null): self
public static function createNewWithMultiline(array $errors, ?string $contentName = null, ?Throwable $previous = null): self
{
$exception = new self($errors);
$exception = new self($errors, $previous);
$exception->contentName = $contentName;

$exception->setMessageTemplate('Content "%contentName%" fields did not validate: %errors%');
$exception->setParameters([
'%errors%' => $exception->generateValidationErrorsMessages(),
'%contentName%' => $exception->contentName !== null ? $exception->contentName : '',
'%contentName%' => $exception->contentName ?? '',
]);
$exception->message = $exception->getBaseTranslation();

Expand Down

0 comments on commit 181f454

Please sign in to comment.