You are here

public function Media::validate in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/media/src/Entity/Media.php \Drupal\media\Entity\Media::validate()
  2. 9 core/modules/media/src/Entity/Media.php \Drupal\media\Entity\Media::validate()

Validates the currently set values.

Return value

\Drupal\Core\Entity\EntityConstraintViolationListInterface A list of constraint violations. If the list is empty, validation succeeded.

Overrides ContentEntityBase::validate

File

core/modules/media/src/Entity/Media.php, line 401

Class

Media
Defines the media entity class.

Namespace

Drupal\media\Entity

Code

public function validate() {
  $media_source = $this
    ->getSource();
  if ($media_source instanceof MediaSourceEntityConstraintsInterface) {
    $entity_constraints = $media_source
      ->getEntityConstraints();
    $this
      ->getTypedData()
      ->getDataDefinition()
      ->setConstraints($entity_constraints);
  }
  if ($media_source instanceof MediaSourceFieldConstraintsInterface) {
    $source_field_name = $media_source
      ->getConfiguration()['source_field'];
    $source_field_constraints = $media_source
      ->getSourceFieldConstraints();
    $this
      ->get($source_field_name)
      ->getDataDefinition()
      ->setConstraints($source_field_constraints);
  }
  return parent::validate();
}