function entity_test_rename_bundle

Renames a bundle for entity_test entities.

Parameters

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

string $bundle_new: The new machine-readable name of the bundle

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

File

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

Code

function entity_test_rename_bundle($bundle_old, $bundle_new, $entity_type = 'entity_test') {
  $bundles = Drupal::state()
    ->get($entity_type . '.bundles') ?: array(
    'entity_test' => array(
      'label' => 'Entity Test Bundle',
    ),
  );
  $bundles[$bundle_new] = $bundles[$bundle_old];
  unset($bundles[$bundle_old]);
  Drupal::state()
    ->set($entity_type . '.bundles', $bundles);
  entity_invoke_bundle_hook('rename', $entity_type, $bundle_old, $bundle_new);
}