Answers.Body: <p>If you really want to do this you would just override CRM_Core_Form, but what is it you're really trying to do because overriding anything is going to cause upgrade problems. My guess is you're really trying to do something that would be better done by implementing the buildForm hook: <a href="https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_buildForm/" rel="nofollow noreferrer">https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_buildForm/</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-06-08T12:17:02.970Z
Answers.Text: Thanks for your reply.  I am well aware off the pitfall of overriding core material.  I would really like to understand why my attempt at this is failing.  By the way, during my research, I went across a civicrm extension that help you manage your overring files,  being php or tpl.  I not sure exactly what are the functions provided to help with the "management" of overrides.
Answers.UserDisplayName: Syxys
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-06-08T15:41:26.503Z
Answers.Text: It works for me but you need to put Quickform.php in "override directory/packages/HTML" not "override directory/packages/HTML/Quickform"
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-06-07T04:15:10.337Z
Answers.LastActivityDate: 2024-06-07T04:15:10.337Z
Answers.UserDisplayName: Demerit
Body: <p>The QuickForm.php file that I want to override is located in civicrm/packages/HTML/Quickform.
  I set my override directory to [civicrm.files]/override_php and put a copy of the originale file in override directory/packages/HTML/Quickform.</p>
  <ol>
  <li>Is the location correct?</li>
  </ol>
  <p>This file define the class HTML_QuickForm and I added a new method call getElements().  The class HTML_QuickForm_Page extend this class which is then extended again to define CRM_Core_Form.
  2. Is my modified HTML_QuickForm class going to be use to extend the descending class or do I need to override (have a copy in my override directory) every descending down to CRM_Core_Form to make it happen.
  3. Should I just override CRM_Core_Form even if the method does not make much sense in the context of CRM_Core_Form?</p>
  <p>Here are my modifications:</p>
  <pre><code> function &amp;getElements()
  {
      if (isset($this-&gt;_elements)) {
          return $this-&gt;_elements[];
      } else {
          $error = PEAR::raiseError(null, QUICKFORM_NONEXIST_ELEMENT, null, E_USER_WARNING, &quot;Element '$elements' does not exist in HTML_QuickForm::getElements()&quot;, 'HTML_QuickForm_Error', true);
          return $error;
      }
  }
  </code></pre>
  <p>Current error message is : undefined method getElements when I try to get the elements array in a buildForm hook.</p>
  <p>Thank for your help</p>
  
Tags: <php>
Title: Overriding core php file that define basic class HTML_Quickform in order to add a new method to CRM_Core_Form
ThreadText: # Overriding core php file that define basic class HTML_Quickform in order to add a new method to CRM_Core_Form
  
  (Asked by: username_0 on 2024-06-06)
  
  The QuickForm.php file that I want to override is located in civicrm/packages/HTML/Quickform.
  I set my override directory to [civicrm.files]/override_php and put a copy of the originale file in override directory/packages/HTML/Quickform.
  
  Is the location correct?
  
  This file define the class HTML_QuickForm and I added a new method call getElements().  The class HTML_QuickForm_Page extend this class which is then extended again to define CRM_Core_Form.
  2. Is my modified HTML_QuickForm class going to be use to extend the descending class or do I need to override (have a copy in my override directory) every descending down to CRM_Core_Form to make it happen.
  3. Should I just override CRM_Core_Form even if the method does not make much sense in the context of CRM_Core_Form?
  Here are my modifications:
   function &getElements()
  {
      if (isset($this->_elements)) {
          return $this->_elements[];
      } else {
          $error = PEAR::raiseError(null, QUICKFORM_NONEXIST_ELEMENT, null, E_USER_WARNING, "Element '$elements' does not exist in HTML_QuickForm::getElements()", 'HTML_QuickForm_Error', true);
          return $error;
      }
  }
  
  Current error message is : undefined method getElements when I try to get the elements array in a buildForm hook.
  Thank for your help
  
  **Tags:** php
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2024-06-07. Score: 0
  
  If you really want to do this you would just override CRM\_Core\_Form, but what is it you're really trying to do because overriding anything is going to cause upgrade problems. My guess is you're really trying to do something that would be better done by implementing the buildForm hook: <https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_buildForm/>
  
  > **Comments:**
  > **username_0**: Thanks for your reply.  I am well aware off the pitfall of overriding core material.  I would really like to understand why my attempt at this is failing.  By the way, during my research, I went across a civicrm extension that help you manage your overring files,  being php or tpl.  I not sure exactly what are the functions provided to help with the "management" of overrides.  
  > **username_1**: It works for me but you need to put Quickform.php in "override directory/packages/HTML" not "override directory/packages/HTML/Quickform"  
  
  ---
  
  