You are here

AssertMediaTrait.php in Gutenberg 8

Same filename and directory in other branches
  1. 8.2 src/AssertMediaTrait.php

Namespace

Drupal\gutenberg

File

src/AssertMediaTrait.php
View source
<?php

namespace Drupal\gutenberg;

use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\file\FileInterface;
use Drupal\media\MediaInterface;

/**
 * Provides utility to assert data.
 *
 * @package Drupal\gutenberg\DataProvider
 */
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));
    }
  }

}

Traits

Namesort descending Description
AssertMediaTrait Provides utility to assert data.