You are here

public function InstallHelper::deleteImportedContent in Drupal 9

Same name and namespace in other branches
  1. 8 core/profiles/demo_umami/modules/demo_umami_content/src/InstallHelper.php \Drupal\demo_umami_content\InstallHelper::deleteImportedContent()

Deletes any content imported by this module.

Return value

$this

File

core/profiles/demo_umami/modules/demo_umami_content/src/InstallHelper.php, line 786

Class

InstallHelper
Defines a helper class for importing default content.

Namespace

Drupal\demo_umami_content

Code

public function deleteImportedContent() {
  $uuids = $this->state
    ->get('demo_umami_content_uuids', []);
  $by_entity_type = array_reduce(array_keys($uuids), function ($carry, $uuid) use ($uuids) {
    $entity_type_id = $uuids[$uuid];
    $carry[$entity_type_id][] = $uuid;
    return $carry;
  }, []);
  foreach ($by_entity_type as $entity_type_id => $entity_uuids) {
    $storage = $this->entityTypeManager
      ->getStorage($entity_type_id);
    $entities = $storage
      ->loadByProperties([
      'uuid' => $entity_uuids,
    ]);
    $storage
      ->delete($entities);
  }
  return $this;
}