How to make deploy operations programmatically ?
Hook Update Deploy Tools is a great contrib module help to make most of site deploy operations programmatically.
Link : https://www.drupal.org/project/hook_update_deploy_tools
CAUTION : Current drupal 8 version is unstable (8.x-1.0-unstable1, 2016-Feb-07 Version), but 8.x-1.x-dev version is usable.
Example: Delete a field instance.
Using contrib module hook_update_deploy_tools
//Drupal 8:
$message = \HookUpdateDeployTools\Fields::deleteInstance('taxonomy_term', 'field_name', 'tags');
//Drupal 7:
$message = HookUpdateDeployTools\Fields::deleteInstance('taxonomy_term', 'field_name', 'tags');
Without Hook Update Deploy Tools
//Drupal 8:
//Drupal 7:
$instance = field_info_instance('node', 'field_name', 'page');//For node
$instance = field_info_instance('taxonomy_term', 'field_name', 'tags');//For taxonomy term
if ($instance) {
field_delete_instance($instance);
}
//D8 (Not tested)
$field_info = \Drupal\field\Entity\FieldConfig::loadByName('node', 'page', 'field_name');
$field_info->delete();
Comments