function Media::validate

Same name in other branches
  1. 9 core/modules/media/src/Entity/Media.php \Drupal\media\Entity\Media::validate()
  2. 10 core/modules/media/src/Entity/Media.php \Drupal\media\Entity\Media::validate()
  3. 11.x core/modules/media/src/Entity/Media.php \Drupal\media\Entity\Media::validate()

Overrides ContentEntityBase::validate

File

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

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

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