function webform_demo_group_uninstall in Webform 8.5
Same name and namespace in other branches
- 6.x modules/webform_demo/webform_demo_group/webform_demo_group.install \webform_demo_group_uninstall()
Implements hook_uninstall().
File
- modules/
webform_demo/ webform_demo_group/ webform_demo_group.install, line 177 - Install, update and uninstall functions for the webform demo group module.
Code
function webform_demo_group_uninstall() {
// Delete groups and group content.
/** @var \Drupal\group\Entity\GroupInterface[] $groups */
$groups = Group::loadMultiple();
foreach ($groups as $group) {
if (in_array($group
->bundle(), [
'webform_group_a',
'webform_group_b',
])) {
/** @var \Drupal\group\Entity\GroupContentInterface[] $group_contents */
$group_contents = $group
->getContent('group_node:webform');
foreach ($group_contents as $group_content) {
// Delete the group content before the entity.
$entity = $group_content
->getEntity();
$group_content
->delete();
$entity
->delete();
}
$group
->delete();
}
}
// Delete users and roles.
$entity_types = [
'user' => 'name',
'user_role' => 'id',
];
foreach ($entity_types as $entity_type => $entity_key) {
$entity_ids = \Drupal::entityQuery($entity_type)
->condition($entity_key, 'webform_group', 'STARTS_WITH')
->execute();
if ($entity_ids) {
$entities = \Drupal::entityTypeManager()
->getStorage($entity_type)
->loadMultiple($entity_ids);
foreach ($entities as $entity) {
$entity
->delete();
}
}
}
// Delete URL aliases.
$table_name = 'path_alias';
$params = [
':alias' => '/webform/group/%',
];
\Drupal::database()
->query('DELETE FROM {' . $table_name . '} WHERE alias LIKE :alias', $params);
}