From 189701bb649d737a51bef6a83544e9bfcff3c923 Mon Sep 17 00:00:00 2001 From: Mathieu Lutfy Date: Tue, 16 Jun 2020 15:42:58 -0400 Subject: [PATCH] Adds CRM_Core_Form::isFormInViewMode and CRM_Core_Form::isFormInEditMode (useful for extensions implementing buildForm) --- CRM/Core/Form.php | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index 481a38f5da..8a7560afae 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -2575,11 +2575,22 @@ class CRM_Core_Form extends HTML_QuickForm_Page { * * @return bool */ - public function isFormInViewOrEditMode() { + protected function isFormInViewOrEditMode() { + return $this->isFormInViewMode() || $this->isFormInEditMode(); + } + + /** + * Is the form in edit mode. + * + * Helper function, notably for extensions implementing the buildForm hook, + * so that they can return early. + * + * @return bool + */ + public function isFormInEditMode() { 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, @@ -2587,6 +2598,18 @@ class CRM_Core_Form extends HTML_QuickForm_Page { ]); } + /** + * Is the form in view mode. + * + * Helper function, notably for extensions implementing the buildForm hook, + * so that they can return early. + * + * @return bool + */ + public function isFormInViewMode() { + return $this->_action == CRM_Core_Action::VIEW; + } + /** * Set the active tab * -- 2.25.1