/** * {@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))); } }