diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index d6035cad3def..5cb75a5b2b08 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -2388,4 +2388,24 @@ public function getCurrency($submittedValues = array()) { return $currency; } + /** + * Is the form in view or edit mode. + * + * The 'addField' function relies on the form action being one of a set list + * of actions. Checking for these allows for an early return. + * + * @return bool + */ + function isFormInViewOrEditMode() { + return in_array($this->_action, [ + CRM_Core_Action::UPDATE, + CRM_Core_Action::ADD, + CRM_Core_Action::VIEW, + CRM_Core_Action::BROWSE, + CRM_Core_Action::BASIC, + CRM_Core_Action::ADVANCED, + CRM_Core_Action::PREVIEW, + ]); + } + } diff --git a/CRM/Core/Form/Search.php b/CRM/Core/Form/Search.php index dabab8620fea..3b3dcda18b6f 100644 --- a/CRM/Core/Form/Search.php +++ b/CRM/Core/Form/Search.php @@ -203,6 +203,9 @@ public function getDefaultContext() { * Add generic fields that specify the contact. */ protected function addContactSearchFields() { + if (!$this->isFormInViewOrEditMode()) { + return; + } $this->addSortNameField(); $this->_group = CRM_Core_PseudoConstant::nestedGroup();