You are here

public function Slideshow::attachConstraints in Media entity slideshow 8

Attaches type-specific constraints to media.

Parameters

MediaInterface $media: Media entity.

Overrides MediaTypeBase::attachConstraints

File

src/Plugin/MediaEntity/Type/Slideshow.php, line 77

Class

Slideshow
Provides media type plugin for Slideshows.

Namespace

Drupal\media_entity_slideshow\Plugin\MediaEntity\Type

Code

public function attachConstraints(MediaInterface $media) {
  parent::attachConstraints($media);
  $source_field_name = $this->configuration['source_field'];

  // Validate slideshow items count.
  $media
    ->getTypedData()
    ->getDataDefinition()
    ->addConstraint('ItemsCount', array(
    'sourceFieldName' => $source_field_name,
  ));
}