You are here

function entity_test_create_bundle in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/system/tests/modules/entity_test/entity_test.module \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'.

41 calls to entity_test_create_bundle()
BulkDeleteTest::setUp in core/modules/field/tests/src/Kernel/BulkDeleteTest.php
Set the default field storage backend for fields created during tests.
ClaroEntityDisplayTest::testExtraFields in core/tests/Drupal/FunctionalJavascriptTests/Theme/ClaroEntityDisplayTest.php
Copied from parent.
CommentCacheTagsTest::createEntity in core/modules/comment/tests/src/Functional/CommentCacheTagsTest.php
Creates the entity to be tested.
CommentNonNodeTest::setUp in core/modules/comment/tests/src/Functional/CommentNonNodeTest.php
CommentNonNodeTest::testsNonIntegerIdEntities in core/modules/comment/tests/src/Functional/CommentNonNodeTest.php
Tests comment fields cannot be added to entity types without integer IDs.

... See full list

File

core/modules/system/tests/modules/entity_test/entity_test.module, line 196
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') ?: [
    $entity_type => [
      'label' => 'Entity Test Bundle',
    ],
  ];
  $bundles += [
    $bundle => [
      'label' => $text ? $text : $bundle,
    ],
  ];
  \Drupal::state()
    ->set($entity_type . '.bundles', $bundles);
  \Drupal::service('entity_bundle.listener')
    ->onBundleCreate($bundle, $entity_type);
}