Created
September 19, 2023 13:20
-
-
Save MatthieuScarset/827e6153b4037db090a1b40a69aeb369 to your computer and use it in GitHub Desktop.
Drupal - Programmatically delete field_group from form and view displays
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
<?php | |
$entity_type = 'node'; | |
$group_name = 'the_group_id'; | |
$context = 'form'; | |
$form_displays = \Drupal::entityTypeManager() | |
->getStorage('entity_form_display') | |
->loadByProperties(['targetEntityType' => 'node']); | |
foreach ($form_displays as $display) { | |
$mode = $display->getMode(); | |
$bundle = $display->getTargetBundle(); | |
if (field_group_exists($group_name, $entity_type, $bundle, $context, $mode)) { | |
$group = field_group_load_field_group($group_name, $entity_type, $bundle, $context, $mode); | |
field_group_delete_field_group($group); | |
} | |
} | |
$context = 'view'; | |
$view_displays = \Drupal::entityTypeManager() | |
->getStorage('entity_view_display') | |
->loadByProperties(['targetEntityType' => 'node']); | |
foreach ($view_displays as $display) { | |
$mode = $display->getMode(); | |
$bundle = $display->getTargetBundle(); | |
if (field_group_exists($group_name, $entity_type, $bundle, $context, $mode)) { | |
$group = field_group_load_field_group($group_name, $entity_type, $bundle, $context, $mode); | |
field_group_delete_field_group($group); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment