Skip to content

Instantly share code, notes, and snippets.

@edutrul
Created June 7, 2017 16:02
Show Gist options
  • Save edutrul/50453a68f0ebcd776755cbaf84d232c0 to your computer and use it in GitHub Desktop.
Save edutrul/50453a68f0ebcd776755cbaf84d232c0 to your computer and use it in GitHub Desktop.
Removes FIELD_NAME from ALL content types on DRUPAL8
/**
* Removes FIELD_NAME from ALL content types.
*/
function MYMODULE_update_8001(&$sandbox) {
$contentTypes = [
'blog_post',
'case_study',
'industry',
'video',
'whitepaper'
];
$entityManager = \Drupal::service('entity.manager');
foreach ($contentTypes as $contentType) {
$fields = $entityManager->getFieldDefinitions('node', $contentType);
if (!empty($fields['FIELD_NAME'])) {
$field = $fields['FIELD_NAME'];
$field->delete();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment