function EntityTestHelper::createBundle
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'.
See also
\Drupal\entity_test\Hook\EntityTestHooks::entityBundleInfo()
59 calls to EntityTestHelper::createBundle()
- BulkDeleteTest::setUp in core/
modules/ field/ tests/ src/ Kernel/ BulkDeleteTest.php - Set the default field storage backend for fields created during tests.
- BundleClassTest::testAmbiguousBundleClassExceptionCreate in core/
tests/ Drupal/ KernelTests/ Core/ Entity/ BundleClassTest.php - Checks exception is thrown if two bundles share the same bundle class.
- BundleClassTest::testAmbiguousBundleClassExceptionEntityTypeRepository in core/
tests/ Drupal/ KernelTests/ Core/ Entity/ BundleClassTest.php - Checks exception is thrown if two entity types share the same bundle class.
- BundleClassTest::testBundleClassShouldExist in core/
tests/ Drupal/ KernelTests/ Core/ Entity/ BundleClassTest.php - Checks exception thrown if a bundle class doesn't exist.
- BundleClassTest::testBundleClassShouldExtendEntityClass in core/
tests/ Drupal/ KernelTests/ Core/ Entity/ BundleClassTest.php - Checks exception thrown if a bundle class doesn't extend the entity class.
File
-
core/
modules/ system/ tests/ modules/ entity_test/ src/ EntityTestHelper.php, line 71
Class
- EntityTestHelper
- Class for the entity API providing several entity types for testing.
Namespace
Drupal\entity_testCode
public static function createBundle($bundle, $text = NULL, $entity_type = 'entity_test') : void {
$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);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.