function entityreference_autocreate_test_uninstall in Entityreference Autocreate 7
Implements hook_uninstall().
It's only a test module, but this is a good place to demonstrate good behaviour.
File
- entityreference_autocreate_test/
entityreference_autocreate_test.install, line 135 - Provides some sample types and fields to test autocreation on
Code
function entityreference_autocreate_test_uninstall() {
$bundles = field_info_bundles('node');
$node_bundles = array(
'song' => 'Song',
'artist' => 'Artist',
);
foreach ($node_bundles as $bundle_name => $bundle_label) {
if (empty($bundles[$bundle_name])) {
// Already gone.
continue;
}
// Delete all content to avoid leaving undefined nodes.
// Potential for timeout here, but whatever.
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'node')
->propertyCondition('type', array(
$bundle_name,
), 'IN');
$result = $query
->execute();
if (!empty($result['node'])) {
foreach ($result['node'] as $node) {
node_delete($node->nid);
}
}
// Now delete type.
node_type_delete($bundle_name);
}
drupal_set_message(t('Removed content types %types', array(
'%types' => implode(', ', $node_bundles),
)));
}