You are here

public function EntityDefinitionUpdateManager::installFieldableEntityType in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Entity/EntityDefinitionUpdateManager.php \Drupal\Core\Entity\EntityDefinitionUpdateManager::installFieldableEntityType()

Installs a new fieldable entity type definition.

Parameters

\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type definition.

\Drupal\Core\Field\FieldStorageDefinitionInterface[] $field_storage_definitions: The entity type's field storage definitions.

Overrides EntityDefinitionUpdateManagerInterface::installFieldableEntityType

File

core/lib/Drupal/Core/Entity/EntityDefinitionUpdateManager.php, line 173

Class

EntityDefinitionUpdateManager
Manages entity definition updates.

Namespace

Drupal\Core\Entity

Code

public function installFieldableEntityType(EntityTypeInterface $entity_type, array $field_storage_definitions) {
  $this
    ->clearCachedDefinitions();
  foreach ($field_storage_definitions as $name => $field_storage_definition) {
    if ($field_storage_definition instanceof BaseFieldDefinition) {
      $field_storage_definition
        ->setName($name)
        ->setTargetEntityTypeId($entity_type
        ->id())
        ->setProvider($entity_type
        ->getProvider())
        ->setTargetBundle(NULL);
    }
  }
  $this->entityTypeListener
    ->onFieldableEntityTypeCreate($entity_type, $field_storage_definitions);
}