Activity tasks - don't add invalid tasks
authorEileen McNaughton <emcnaughton@wikimedia.org>
Sun, 25 Jul 2021 22:04:35 +0000 (10:04 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Mon, 26 Jul 2021 00:57:46 +0000 (12:57 +1200)
Instead of 'handling the task code building invalid tasks - #20945' - this proposes to only attempt
to add a page if it is for a valid task. This keeps the grouchiness in the generic controller
to warn us of other mistakes.

This code is pretty fugly! However, it really is just called internally within this class.

CRM/Activity/StateMachine/Search.php
CRM/Activity/Task.php

index 56c408af124806feda6ef04734aaeae66c278dcf..28a3c8815b01e732c27e4a86d1d9bc502179a52b 100644 (file)
@@ -35,16 +35,10 @@ class CRM_Activity_StateMachine_Search extends CRM_Core_StateMachine {
     $this->_pages = [];
 
     $this->_pages['CRM_Activity_Form_Search'] = NULL;
-    list($task, $result) = $this->taskName($controller, 'Search');
+    list($task) = $this->taskName($controller, 'Search');
     $this->_task = $task;
-
-    if (is_array($task)) {
-      foreach ($task as $t) {
-        $this->_pages[$t] = NULL;
-      }
-    }
-    else {
-      $this->_pages[$task] = NULL;
+    foreach ($task as $t) {
+      $this->_pages[$t] = NULL;
     }
 
     $this->addSequentialPages($this->_pages, $action);
@@ -63,7 +57,7 @@ class CRM_Activity_StateMachine_Search extends CRM_Core_StateMachine {
    * @return array
    *   the name of the form that will handle the task
    */
-  public function taskName($controller, $formName = 'Search') {
+  protected function taskName($controller, $formName = 'Search') {
     // total hack, check POST vars and then session to determine stuff
     $value = $_POST['task'] ?? NULL;
     if (!isset($value)) {
index 94c1d62779ada35ebe02b62d9587945c27e1b66c..a2305a2c55b5b0a5c09e103177b7c71274522d0d 100644 (file)
@@ -156,11 +156,10 @@ class CRM_Activity_Task extends CRM_Core_Task {
       // make the print task by default
       $value = self::TASK_PRINT;
     }
-
-    return [
-      self::$_tasks[$value]['class'],
-      self::$_tasks[$value]['result'],
-    ];
+    if (isset(self::$_tasks[$value])) {
+      return [[self::$_tasks[$value]['class']], self::$_tasks[$value]['result']];
+    }
+    return [[], NULL];
   }
 
 }