function TemporaryJsonapiFileFieldUploader::validate

Same name in other branches
  1. 9 core/modules/jsonapi/src/Controller/TemporaryJsonapiFileFieldUploader.php \Drupal\jsonapi\Controller\TemporaryJsonapiFileFieldUploader::validate()
  2. 8.9.x core/modules/jsonapi/src/Controller/TemporaryJsonapiFileFieldUploader.php \Drupal\jsonapi\Controller\TemporaryJsonapiFileFieldUploader::validate()
  3. 11.x core/modules/jsonapi/src/Controller/TemporaryJsonapiFileFieldUploader.php \Drupal\jsonapi\Controller\TemporaryJsonapiFileFieldUploader::validate()

Validates the file.

@todo this method is unused in this class because file validation needs to be split up in 2 steps in ::handleFileUploadForField(). Add a deprecation notice as soon as a central core file upload service can be used in this class. See https://www.drupal.org/project/drupal/issues/2940383

Parameters

\Drupal\file\FileInterface $file: The file entity to validate.

array $validators: An array of upload validators to pass to FileValidator.

Return value

\Drupal\Core\Entity\EntityConstraintViolationListInterface The list of constraint violations, if any.

File

core/modules/jsonapi/src/Controller/TemporaryJsonapiFileFieldUploader.php, line 399

Class

TemporaryJsonapiFileFieldUploader
Reads data from an upload stream and creates a corresponding file entity.

Namespace

Drupal\jsonapi\Controller

Code

protected function validate(FileInterface $file, array $validators) {
    $violations = $file->validate();
    // Remove violations of inaccessible fields as they cannot stem from our
    // changes.
    $violations->filterByFieldAccess();
    // Validate the file based on the field definition configuration.
    $violations->addAll($this->fileValidator
        ->validate($file, $validators));
    return $violations;
}

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