Last active
November 3, 2015 09:56
-
-
Save andeersg/0f10658ee9646544542b to your computer and use it in GitHub Desktop.
Delete all instances and the field in Drupal 7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$field_name = ''; | |
$entity_name = ''; | |
$entity = entity_get_info($entity_name); | |
foreach ($entity['bundles'] as $key => $value) { | |
$field_instance = field_info_instances($entity_name, $key); | |
$instance = $field_instance[$field_name]; | |
field_delete_instance($instance); | |
} | |
try { | |
field_delete_field($field_name); | |
} | |
catch (Exception $e) { | |
dpm($e->getMessage()); | |
dpm('Field is probably present on other entities'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment