/** * Provides the node submission form. * * @param \Drupal\crm_core_activity\Entity\ActivityType $crm_core_activity_type * The activity type to add. * @param \Drupal\crm_core_contact\Entity\Contact $crm_core_contact * (optional) The contact the activity will be assigned. If left blank, the * Form will show a field to select a contact. * @return array * A node submission form. */ public function add(ActivityType $crm_core_activity_type, Contact $crm_core_contact = NULL) { $values = array('type' => $crm_core_activity_type->id()); if ($crm_core_contact) { $values['activity_participants'] = array(array('target_id' => $crm_core_contact->id())); } $activity = Activity::create($values); $form = $this->entityFormBuilder()->getForm($activity); return $form; }
/** * {@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))); } }