Set formBuilt to TRUE when, erm, it is built
authorEileen McNaughton <emcnaughton@wikimedia.org>
Sun, 17 Dec 2023 20:45:11 +0000 (09:45 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Sun, 17 Dec 2023 20:46:39 +0000 (09:46 +1300)
CRM/Contribute/Form/Contribution.php
CRM/Core/Form.php

index abccf9acd35916203bf18986ff4ad762139c75e1..6f7f033eb7adde95594ce2f8c4f8c992b77629ac 100644 (file)
@@ -2401,10 +2401,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
    */
   public function getPriceSetID(): ?int {
     $priceSetID = $this->getSubmittedValue('price_set_id') ?: CRM_Utils_Request::retrieve('priceSetId', 'Integer');
-    // Ideally we would use $this->isFormBuilt() here to know when to access the _POST
-    // array directly. However, the parent sets isBuilt before, building the form,
-    // rather than after.
-    if (!$priceSetID && !empty($this->getSubmitValue('price_set_id'))) {
+    if (!$this->isFormBuilt() && !empty($this->getSubmitValue('price_set_id'))) {
       return (int) $this->getSubmitValue('price_set_id');
     }
     return $priceSetID ?? NULL;
index f31e0ac0fbeb76860ac3d362ae54c1e84bda93b2..6cab90d98504a9e9e40c52781b4308fcb0985ec0 100644 (file)
@@ -726,10 +726,6 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
    * buildQuickForm.
    */
   public function buildForm() {
-    // @todo - move this to the end of the function - then it can be checked
-    // ie $this->isBuilt() to determine whether variables are not yet in getSubmittedValues()
-    $this->_formBuilt = TRUE;
-
     $this->preProcess();
 
     CRM_Utils_Hook::preProcess(get_class($this), $this);
@@ -787,6 +783,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
     // it's already been initialized.
     self::$_template->ensureVariablesAreAssigned($this->expectedSmartyVariables);
     self::$_template->addExpectedTabHeaderKeys();
+    $this->_formBuilt = TRUE;
   }
 
   /**