function RecipeFileException::fromViolationList

Same name in other branches
  1. 10 core/lib/Drupal/Core/Recipe/RecipeFileException.php \Drupal\Core\Recipe\RecipeFileException::fromViolationList()

Creates an instance of this exception from a set of validation errors.

Parameters

string $path: The path of the offending recipe file.

\Symfony\Component\Validator\ConstraintViolationList $violations: The list of validation constraint violations.

Return value

static

1 call to RecipeFileException::fromViolationList()
Recipe::parse in core/lib/Drupal/Core/Recipe/Recipe.php
Parses and validates a recipe.yml file.

File

core/lib/Drupal/Core/Recipe/RecipeFileException.php, line 50

Class

RecipeFileException
@internal This API is experimental.

Namespace

Drupal\Core\Recipe

Code

public static function fromViolationList(string $path, ConstraintViolationList $violations) : static {
    $lines = [
        "Validation errors were found in {$path}:",
    ];
    foreach ($violations as $violation) {
        $lines[] = sprintf('- %s: %s', $violation->getPropertyPath(), $violation->getMessage());
    }
    return new static($path, implode("\n", $lines), $violations);
}

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