You are here

function entity_schema_test_entity_bundle_create in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/system/tests/modules/entity_schema_test/entity_schema_test.module \entity_schema_test_entity_bundle_create()

Implements hook_entity_bundle_create().

File

core/modules/system/tests/modules/entity_schema_test/entity_schema_test.module, line 73
Test module for the entity API providing a bundle field.

Code

function entity_schema_test_entity_bundle_create($entity_type_id, $bundle) {
  if ($entity_type_id == 'entity_test' && $bundle == 'custom') {
    $entity_type = \Drupal::entityManager()
      ->getDefinition($entity_type_id);
    $field_definitions = entity_schema_test_entity_bundle_field_info($entity_type, $bundle);
    $field_definitions['custom_bundle_field']
      ->setTargetEntityTypeId($entity_type_id)
      ->setTargetBundle($bundle);

    // Notify the entity storage that we just created a new field.
    \Drupal::entityManager()
      ->onFieldDefinitionCreate($field_definitions['custom_bundle_field']);
  }
}