Creates a new bundle for test_entity entities.
$bundle: The machine-readable name of the bundle.
$text: The human-readable name of the bundle. If none is provided, the machine name will be used.
function field_test_create_bundle($bundle, $text = NULL) {
$bundles = Drupal::state()
->get('field_test.bundles') ?: array(
'test_bundle' => array(
'label' => 'Test Bundle',
),
);
$bundles += array(
$bundle => array(
'label' => $text ? $text : $bundle,
),
);
Drupal::state()
->set('field_test.bundles', $bundles);
$info = entity_get_info();
foreach ($info as $type => $type_info) {
if ($type_info['module'] == 'field_test') {
entity_invoke_bundle_hook('create', $type, $bundle);
}
}
}