/** * {@inheritdoc} */ public static function preDelete(EntityStorageInterface $storage, array $entities) { parent::preDelete($storage, $entities); foreach ($entities as $entity) { $storage->deleteAssignedShortcutSets($entity); // Next, delete the shortcuts for this set. $shortcut_ids = \Drupal::entityQuery('shortcut')->condition('shortcut_set', $entity->id(), '=')->execute(); $controller = \Drupal::entityManager()->getStorage('shortcut'); $entities = $controller->loadMultiple($shortcut_ids); $controller->delete($entities); } }
/** * {@inheritdoc} */ public static function preDelete(EntityStorageInterface $storage, array $entities) { parent::preDelete($storage, $entities); // Only load terms without a parent, child terms will get deleted too. entity_delete_multiple('taxonomy_term', $storage->getToplevelTids(array_keys($entities))); }
/** * {@inheritdoc} */ public static function preDelete(EntityStorageInterface $storage, array $entities) { $registration_storage = \Drupal::entityManager()->getStorage('registration'); /** @var \Drupal\rng\EventManagerInterface $event_manager */ $event_manager = \Drupal::service('rng.event_manager'); /** @var \Drupal\rng\RegistrationTypeInterface $registration_type */ foreach ($entities as $registration_type) { // Remove entity field references in // $event->{EventManagerInterface::FIELD_REGISTRATION_TYPE} $event_types = $event_manager->getEventTypes(); foreach ($event_types as $entity_type => $bundles) { $event_storage = \Drupal::entityManager()->getStorage($entity_type); foreach ($bundles as $bundle => $event_type) { $bundle_key = \Drupal::entityManager()->getDefinition($entity_type)->getKey('bundle'); $ids = $event_storage->getQuery()->condition($bundle_key, $bundle)->condition(EventManagerInterface::FIELD_REGISTRATION_TYPE, $registration_type->id())->execute(); foreach ($ids as $id) { $event_manager->getMeta($event_storage->load($id))->removeRegistrationType($registration_type->id())->save(); } } } // Remove registrations. $ids = $registration_storage->getQuery()->condition('type', $registration_type->id())->execute(); $registrations = $registration_storage->loadMultiple($ids); $registration_storage->delete($registrations); } parent::preDelete($storage, $entities); }
/** * {@inheritdoc} * * @todo This does not scale. * * Deleting a contact type with thousands of contact records associated will * run into execution timeout. */ public static function preDelete(EntityStorageInterface $storage, array $entities) { parent::preDelete($storage, $entities); $ids = array_map(function (EntityInterface $entity) { return $entity->id(); }, $entities); // Delete all instances of the given type. $results = \Drupal::entityQuery('crm_core_contact')->condition('type', $ids, 'IN')->execute(); if (!empty($results)) { $contacts = Contact::loadMultiple($results); \Drupal::entityManager()->getStorage('crm_core_contact')->delete($contacts); watchdog('crm_core_contact', 'Delete !count contacts due to deletion of contact type.', array('!count' => count($results)), WATCHDOG_INFO); } }
/** * {@inheritdoc} * * @todo This does not scale. * * Deleting a activity type with thousands of activities records associated * will run into execution timeout. */ public static function preDelete(EntityStorageInterface $storage, array $entities) { parent::preDelete($storage, $entities); $ids = array_map(function (EntityInterface $entity) { return $entity->id(); }, $entities); // Delete all instances of the given type. $results = \Drupal::entityQuery('crm_core_activity')->condition('type', $ids, 'IN')->execute(); if (!empty($results)) { $activities = Activity::loadMultiple($results); \Drupal::entityManager()->getStorage('crm_core_activity')->delete($activities); // @todo Handle singular and plural. \Drupal::logger('crm_core_activity')->info('Delete !count activities due to deletion of activity type.', array('!count' => count($results))); } }
/** * {@inheritdoc} */ public static function preDelete(EntityStorageInterface $storage, array $entities) { parent::preDelete($storage, $entities); foreach ($entities as $queue) { $queue->getHandlerPlugin()->onQueuePreDelete($queue, $storage); } }