You are here

public function SchemaFactory::getSourceEntityPlugin in Schemata 8

Load the Entity Type Plugin to drive schema content.

This method should incorporate any "validation" of the entity type.

It is broken out in part to facilitate test creation.

Parameters

string $entity_type_id: Entity Type ID.

Return value

\Drupal\Core\Entity\EntityTypeInterface The Entity Type plugin.

Throws

\Drupal\Component\Plugin\Exception\PluginNotFoundException Thrown if $entity_type_id does not refer to a valid Entity Type plugin.

\InvalidArgumentException Thrown if $entity_type_id does not refer to a Content Entity Type.

See also

\Drupal\Tests\schemata\Functional\ValidateSchemaTest::validateSchemaAsJsonSchema()

1 call to SchemaFactory::getSourceEntityPlugin()
SchemaFactory::create in src/SchemaFactory.php
Assemble a schema object based on the requested entity type.

File

src/SchemaFactory.php, line 161

Class

SchemaFactory
Create an object of type Drupal\schemata\Schema\SchemaInterface.

Namespace

Drupal\schemata

Code

public function getSourceEntityPlugin($entity_type_id) {
  $entity_type_plugin = $this->entityTypeManager
    ->getDefinition($entity_type_id);
  if (!$entity_type_plugin
    ->entityClassImplements(ContentEntityInterface::class)) {
    throw new \InvalidArgumentException(sprintf('Entity Type %s is not a content entity. Only content entities are supported at this time.', $entity_type_id));
  }
  return $entity_type_plugin;
}