Adds CRM_Core_Form::isFormInViewMode and CRM_Core_Form::isFormInEditMode (useful...
authorMathieu Lutfy <mathieu@symbiotic.coop>
Tue, 16 Jun 2020 19:42:58 +0000 (15:42 -0400)
committerMathieu Lutfy <mathieu@bidon.ca>
Wed, 17 Jun 2020 13:49:16 +0000 (09:49 -0400)
CRM/Core/Form.php

index 481a38f5dad8af55dd5b66396ab385e8285ec604..8a7560afaeabfacefb9c50b2ded8a09f7b41741d 100644 (file)
@@ -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
    *