trait AssertMediaTrait in Gutenberg 8.2
Same name and namespace in other branches
- 8 src/AssertMediaTrait.php \Drupal\gutenberg\AssertMediaTrait
Provides utility to assert data.
@package Drupal\gutenberg\DataProvider
Hierarchy
- trait \Drupal\gutenberg\AssertMediaTrait
2 files declare their use of AssertMediaTrait
- FileEntityDataProvider.php in src/
DataProvider/ FileEntityDataProvider.php - MediaEntityDataProvider.php in src/
DataProvider/ MediaEntityDataProvider.php
File
- src/
AssertMediaTrait.php, line 14
Namespace
Drupal\gutenbergView source
trait AssertMediaTrait {
/**
* Assert if provided entity is type of FileInterface.
*
* @param \Drupal\Core\Entity\ContentEntityInterface $entity
* Entity instance to check.
*
* @throws \Exception
*/
protected function assertIsFileEntity(ContentEntityInterface $entity) {
if (!$entity instanceof FileInterface) {
throw new \Exception(sprintf('Entity must by type of %s.', FileInterface::class));
}
}
/**
* Assert if provided entity is type of MediaInterface.
*
* @param \Drupal\Core\Entity\ContentEntityInterface $entity
* Entity instance to check.
*
* @throws \Exception
*/
protected function assertIsMediaEntity(ContentEntityInterface $entity) {
if (!$entity instanceof MediaInterface) {
throw new \Exception(sprintf('Entity must by type of %s.', MediaInterface::class));
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AssertMediaTrait:: |
protected | function | Assert if provided entity is type of FileInterface. | |
AssertMediaTrait:: |
protected | function | Assert if provided entity is type of MediaInterface. |