public function Pinterest::attachConstraints in Media entity Pinterest 8
Attaches type-specific constraints to media.
Parameters
MediaInterface $media: Media entity.
Overrides MediaTypeBase::attachConstraints
File
- src/
Plugin/ MediaEntity/ Type/ Pinterest.php, line 196
Class
- Provides media type plugin for Pinterest.
Namespace
Drupal\media_entity_pinterest\Plugin\MediaEntity\TypeCode
public function attachConstraints(MediaInterface $media) {
parent::attachConstraints($media);
if (isset($this->configuration['source_field'])) {
$source_field_name = $this->configuration['source_field'];
if ($media
->hasField($source_field_name)) {
foreach ($media
->get($source_field_name) as &$embed_code) {
/** @var \Drupal\Core\TypedData\DataDefinitionInterface $typed_data */
$typed_data = $embed_code
->getDataDefinition();
$typed_data
->addConstraint('PinEmbedCode');
}
}
}
}