You are here

trait AssertMediaTrait in Gutenberg 8

Same name and namespace in other branches
  1. 8.2 src/AssertMediaTrait.php \Drupal\gutenberg\AssertMediaTrait

Provides utility to assert data.

@package Drupal\gutenberg\DataProvider

Hierarchy

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\gutenberg
View 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

Namesort descending Modifiers Type Description Overrides
AssertMediaTrait::assertIsFileEntity protected function Assert if provided entity is type of FileInterface.
AssertMediaTrait::assertIsMediaEntity protected function Assert if provided entity is type of MediaInterface.