Hook Update Deploy Tools: to delete fields
If you have used a Feature and removed a field from the Feature and reverted, only to find the field still present in your content type, this update is for you. Hook Update Deploy Tools now has a method (as of version 7.x-1.6) to remove a field instance from the content type. The method gives feedback as to the removal of the field, checks to see that it was removed, and reports whether it was the only instance of the field or not. The feedback and associated logging is what makes this essential when using a hands-free code deployment strategy.
Code like this is all it takes in a hook_update_N in the feature.install to delete field instances.
<?php
/**
* Remove author field from blog.
*/
function blog_post_update_7011() {
$message = HookUpdateDeployTools\Fields::deleteInstance('field_author_leadership', 'blog', 'node');
return $message;
}
/**
* Remove published date field from blog.
*/
function blog_post_update_7013() {
$message = HookUpdateDeployTools\Fields::deleteInstance('field_date_updated_reviewed', 'blog', 'node');
return $message;
}
?>
And this is what the feedback at the terminal reveals (Also logged to Watchdog):