Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ProjectRelease.php

function 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\update

Code

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));
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal