function EntitySchemaSubscriber::onEntityTypeCreate

Same name in this branch
  1. 10 core/modules/workspaces/src/EventSubscriber/EntitySchemaSubscriber.php \Drupal\workspaces\EventSubscriber\EntitySchemaSubscriber::onEntityTypeCreate()
Same name in other branches
  1. 9 core/modules/workspaces/src/EventSubscriber/EntitySchemaSubscriber.php \Drupal\workspaces\EventSubscriber\EntitySchemaSubscriber::onEntityTypeCreate()
  2. 9 core/modules/system/tests/modules/entity_test_update/src/EventSubscriber/EntitySchemaSubscriber.php \Drupal\entity_test_update\EventSubscriber\EntitySchemaSubscriber::onEntityTypeCreate()
  3. 8.9.x core/modules/workspaces/src/EventSubscriber/EntitySchemaSubscriber.php \Drupal\workspaces\EventSubscriber\EntitySchemaSubscriber::onEntityTypeCreate()
  4. 8.9.x core/modules/system/tests/modules/entity_test_update/src/EventSubscriber/EntitySchemaSubscriber.php \Drupal\entity_test_update\EventSubscriber\EntitySchemaSubscriber::onEntityTypeCreate()
  5. 11.x core/modules/workspaces/src/EventSubscriber/EntitySchemaSubscriber.php \Drupal\workspaces\EventSubscriber\EntitySchemaSubscriber::onEntityTypeCreate()
  6. 11.x core/modules/system/tests/modules/entity_test_update/src/EventSubscriber/EntitySchemaSubscriber.php \Drupal\entity_test_update\EventSubscriber\EntitySchemaSubscriber::onEntityTypeCreate()

Overrides EntityTypeEventSubscriberTrait::onEntityTypeCreate

File

core/modules/system/tests/modules/entity_test_update/src/EventSubscriber/EntitySchemaSubscriber.php, line 58

Class

EntitySchemaSubscriber
Defines a class for listening to entity schema changes.

Namespace

Drupal\entity_test_update\EventSubscriber

Code

public function onEntityTypeCreate(EntityTypeInterface $entity_type) {
    // Only add the new base field when a test needs it.
    if (!$this->state
        ->get('entity_test_update.install_new_base_field_during_create', FALSE)) {
        return;
    }
    // Add a new base field when the entity type is created.
    $definitions = $this->state
        ->get('entity_test_update.additional_base_field_definitions', []);
    $definitions['new_base_field'] = BaseFieldDefinition::create('string')->setName('new_base_field')
        ->setLabel(new TranslatableMarkup('A new base field'));
    $this->state
        ->set('entity_test_update.additional_base_field_definitions', $definitions);
    $this->entityDefinitionUpdateManager
        ->installFieldStorageDefinition('new_base_field', 'entity_test_update', 'entity_test_update', $definitions['new_base_field']);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.