function entity_test_create_bundle

Creates a new bundle for entity_test entities.

Parameters

string $bundle: The machine-readable name of the bundle.

string $text: (optional) The human-readable name of the bundle. If none is provided, the machine name will be used.

string $entity_type: (optional) The entity type for which the bundle is created. Defaults to 'entity_test'.

3 calls to entity_test_create_bundle()
EntityQueryTest::setUp in drupal/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php
Sets up Drupal unit test environment.
FieldImportCreateTest::testImportCreateDefault in drupal/core/modules/field/lib/Drupal/field/Tests/FieldImportCreateTest.php
Tests creating fields and instances during default config import.
FieldImportDeleteTest::testImportDelete in drupal/core/modules/field/lib/Drupal/field/Tests/FieldImportDeleteTest.php
Tests deleting fields and instances as part of config import.

File

drupal/core/modules/system/tests/modules/entity_test/entity_test.module, line 79
Test module for the entity API providing several entity types for testing.

Code

function entity_test_create_bundle($bundle, $text = NULL, $entity_type = 'entity_test') {
  $bundles = Drupal::state()
    ->get($entity_type . '.bundles') ?: array(
    'entity_test' => array(
      'label' => 'Entity Test Bundle',
    ),
  );
  $bundles += array(
    $bundle => array(
      'label' => $text ? $text : $bundle,
    ),
  );
  Drupal::state()
    ->set($entity_type . '.bundles', $bundles);
  entity_invoke_bundle_hook('create', $entity_type, $bundle);
}