Avoid PHP notices on activity form
authorBradley Taylor <hello@brad-taylor.co.uk>
Sun, 30 Jan 2022 10:44:07 +0000 (10:44 +0000)
committerBradley Taylor <hello@brad-taylor.co.uk>
Mon, 31 Jan 2022 20:20:37 +0000 (20:20 +0000)
CRM/Activity/Form/Activity.php

index 819e2c76076b406065b163aa04122841f656e697..4845e864e13d4be27282d8b717fc12654de045e3 100644 (file)
@@ -364,13 +364,15 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task {
       );
     }
 
+    $activityTypeDescription = NULL;
     if ($this->_activityTypeId) {
-      // Set activity type name and description to template.
       list($this->_activityTypeName, $activityTypeDescription) = CRM_Core_BAO_OptionValue::getActivityTypeDetails($this->_activityTypeId);
-      $this->assign('activityTypeName', $this->_activityTypeName);
-      $this->assign('activityTypeDescription', $activityTypeDescription);
     }
 
+    // Set activity type name and description to template.
+    $this->assign('activityTypeName', $this->_activityTypeName ?? FALSE);
+    $this->assign('activityTypeDescription', $activityTypeDescription ?? FALSE);
+
     // set user context
     $urlParams = $urlString = NULL;
     $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this);
@@ -1235,6 +1237,9 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task {
    * For the moment this is just pulled from preProcess
    */
   public function assignActivityType() {
+    // Default array with required key for Smarty template
+    $activityTypeNameAndLabel = ['machineName' => FALSE];
+
     if ($this->_activityTypeId) {
       $activityTypeDisplayLabels = $this->getActivityTypeDisplayLabels();
       if ($activityTypeDisplayLabels[$this->_activityTypeId]) {
@@ -1242,7 +1247,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task {
 
         // At the moment this is duplicating other code in this section, but refactoring in small steps.
         $activityTypeObj = new CRM_Activity_BAO_ActivityType($this->_activityTypeId);
-        $this->assign('activityTypeNameAndLabel', $activityTypeObj->getActivityType());
+        $activityTypeNameAndLabel = $activityTypeObj->getActivityType();
       }
       // Set title.
       if (isset($activityTypeDisplayLabels)) {
@@ -1262,6 +1267,8 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task {
         }
       }
     }
+
+    $this->assign('activityTypeNameAndLabel', $activityTypeNameAndLabel);
   }
 
 }