Skip to content

Instantly share code, notes, and snippets.

@batigolix
Last active February 10, 2016 10:59
Show Gist options
  • Save batigolix/f8e0a3dd916f237a7383 to your computer and use it in GitHub Desktop.
Save batigolix/f8e0a3dd916f237a7383 to your computer and use it in GitHub Desktop.
Delete custom fields in Drupal 7
/**
* Delete field
*/
function mymodule_update_7000() {
$fields = array(
'field_myfield1',
'field_myfield2',
);
foreach ($fields as $field) {
if ($instance = field_info_instance('node', $field, 'page')) {
field_delete_instance($instance);
}
}
field_purge_batch(count($fields));
}
/**
* Implements hook_uninstall().
*/
function nexteuropa_map_uninstall() {
$t = get_t();
// Deletes the field create by this module.
$fields = array('map_layers');
foreach ($fields as $field) {
if ($instance = field_info_instance('map', $field, 'map')) {
field_delete_instance($instance);
}
}
field_purge_batch(count($fields));
drupal_set_message($t('Nexteuropa map has been uninstalled. Map layers field has been deleted.'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment