Skip to content

Commit

Permalink
Merge pull request #817 from droptica/ISSUE-3294037-d-mautic-uninstal…
Browse files Browse the repository at this point in the history
…l-problem

Issue #3294037 by mkrawczyk, gpietrzak: Deletes node references to d_…
  • Loading branch information
grzegorz-pietrzak-droptica authored Aug 2, 2022
2 parents 9666c28 + 32b9cf0 commit 3832fd5
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions modules/custom/d_mautic/d_mautic.install
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,34 @@ function d_mautic_install() {
Drupal::service('d_update')
->updateConfigurations('module/d_mautic', 'd_mautic.init');
}

/**
* Implements hook_uninstall().
*
* Deletes node references to d_mautic paragraph after uninstalling module.
*/
function d_mautic_uninstall() {
$ids = [];
$allParagraphs = \Drupal::entityTypeManager()->getStorage('paragraph')->loadMultiple();

foreach ($allParagraphs as $paragraph) {
$type = $paragraph->bundle();
if ($type === 'd_mautic') {
$ids[] = $paragraph->get('id')->getValue()[0]['value'];
}
}

$allNodes = \Drupal::entityTypeManager()->getStorage('node')->loadMultiple();
foreach ($allNodes as $node) {
if ($node->hasField('field_page_section')) {
$page_section = $node->get('field_page_section')->getValue();
foreach ($page_section as $index => $section) {
if (in_array($section['target_id'], $ids)) {
unset($page_section[$index]);
$node->field_page_section = $page_section;
$node->save();
}
}
}
}
}

0 comments on commit 3832fd5

Please sign in to comment.