function ProjectRelease::validateReleaseData
Same name in other branches
- 9 core/modules/update/src/ProjectRelease.php \Drupal\update\ProjectRelease::validateReleaseData()
- 10 core/modules/update/src/ProjectRelease.php \Drupal\update\ProjectRelease::validateReleaseData()
Validates the project release data.
Parameters
array $data: The project release data.
Throws
\UnexpectedValueException Thrown if project release data is not valid.
1 call to ProjectRelease::validateReleaseData()
- ProjectRelease::createFromArray in core/
modules/ update/ src/ ProjectRelease.php - Creates a ProjectRelease instance from an array.
File
-
core/
modules/ update/ src/ ProjectRelease.php, line 141
Class
- ProjectRelease
- Provides a project release value object.
Namespace
Drupal\updateCode
private static function validateReleaseData(array $data) : void {
$not_blank_constraints = [
new Type('string'),
new NotBlank(),
];
$collection_constraint = new Collection([
'fields' => [
'version' => $not_blank_constraints,
'date' => new Optional([
new Type('numeric'),
]),
'core_compatible' => new Optional([
new Type('boolean'),
]),
'core_compatibility_message' => new Optional($not_blank_constraints),
'status' => new Choice([
'published',
'unpublished',
]),
'download_link' => new Optional($not_blank_constraints),
'release_link' => $not_blank_constraints,
'terms' => new Optional([
new Type('array'),
new Collection([
'Release type' => new Optional([
new Type('array'),
]),
]),
]),
],
'allowExtraFields' => TRUE,
]);
$violations = Validation::createValidator()->validate($data, $collection_constraint);
if (count($violations)) {
foreach ($violations as $violation) {
$violation_messages[] = "Field " . $violation->getPropertyPath() . ": " . $violation->getMessage();
}
throw new \UnexpectedValueException('Malformed release data: ' . implode(",\n", $violation_messages));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.