CRM-21507 Fix error when creating case activities
authorSean Madsen <sean@seanmadsen.com>
Sun, 3 Dec 2017 17:03:40 +0000 (12:03 -0500)
committerSean Madsen <sean@seanmadsen.com>
Sun, 3 Dec 2017 17:03:40 +0000 (12:03 -0500)
Before: When adding a new activity to a case, an error message
"Activity Separation is a required field" appears and prevents the user
from submitting the form. There is no way to get around this error.

After: The user can create case activities without hitting this error
message. Also the error still displays as expected when creating
non-case activities that have multiple target contacts.

This changes fixes a regression caused by my fix for CRM-21419.

CRM/Activity/Form/Activity.php
CRM/Case/Form/Activity.php

index 58d7eadff2fb64eb957ea421c1b5d15cfdb4c5f6..53e64c546d67bd4289f83817afc24f918ea6d04f 100644 (file)
@@ -119,6 +119,23 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task {
 
   protected $unsavedWarn = TRUE;
 
+  /*
+   * Is it possible to create separate activities with this form?
+   *
+   * When TRUE, the form will ask whether the user wants to create separate
+   * activities (if the user has specified multiple contacts in the "with"
+   * field).
+   *
+   * When FALSE, the form will create one activity with all contacts together
+   * and won't ask the user anything.
+   *
+   * Note: This is a class property so that child classes can turn off this
+   * behavior (e.g. in CRM_Case_Form_Activity)
+   *
+   * @var boolean
+   */
+  protected $supportsActivitySeparation = TRUE;
+
   /**
    * Explicitly declare the entity api name.
    *
@@ -839,12 +856,16 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task {
     if ((!empty($fields['followup_activity_subject']) || !empty($fields['followup_date'])) && empty($fields['followup_activity_type_id'])) {
       $errors['followup_activity_subject'] = ts('Follow-up Activity type is a required field.');
     }
+
+    // Check that a value has been set for the "activity separation" field if needed
+    $separationIsPossible = $self->supportsActivitySeparation;
     $actionIsAdd = $self->_action == CRM_Core_Action::ADD;
     $hasMultipleTargetContacts = !empty($fields['target_contact_id']) && strpos($fields['target_contact_id'], ',') !== FALSE;
     $separationFieldIsEmpty = empty($fields['separation']);
-    if ($actionIsAdd && $hasMultipleTargetContacts && $separationFieldIsEmpty) {
+    if ($separationIsPossible && $actionIsAdd && $hasMultipleTargetContacts && $separationFieldIsEmpty) {
       $errors['separation'] = ts('Activity Separation is a required field.');
     }
+
     return $errors;
   }
 
index 9e913a49268833f6d3aa3f36e7b888246fda13c0..d8279136b31e1270d9d6e86a00a9d2e23a46c865 100644 (file)
@@ -197,6 +197,11 @@ class CRM_Case_Form_Activity extends CRM_Activity_Form_Activity {
       }
     }
 
+    // Turn off the prompt which asks the user if they want to create separate
+    // activities when specifying multiple contacts "with" a new activity.
+    // Instead, always create one activity with all contacts together.
+    $this->supportsActivitySeparation = FALSE;
+
     $session = CRM_Core_Session::singleton();
     $session->pushUserContext($url);
   }