Created
June 7, 2017 16:02
-
-
Save edutrul/50453a68f0ebcd776755cbaf84d232c0 to your computer and use it in GitHub Desktop.
Removes FIELD_NAME from ALL content types on DRUPAL8
This file contains hidden or 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
/** | |
* 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