Created
February 6, 2017 19:45
-
-
Save mlutfy/106a73dc93b06bae9e0a3de0920a10e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Implements hook_civicrm_buildForm() is a completely overkill way. | |
* Searches for an override class named after the initial $formName | |
* and calls its buildForm(). | |
* | |
* Ex: for a $formName "CRM_Case_Form_CaseView", it will: | |
* - try to find * CRM/Symbiotic/Case/Form/CaseView.php, | |
* - require_once the file, instanciate an object, and | |
* - call its buildForm() function. | |
* | |
* Why so overkill? My buildForm() implementations tend to become | |
* really big and numerous, and even if I split up into multiple | |
* functions, it still makes a really long php file. | |
*/ | |
function symbiocivicrm_civicrm_buildForm($formName, &$form) { | |
$formName = str_replace('CRM_', 'CRM_Symbiotic_', $formName); | |
$parts = explode('_', $formName); | |
$filename = dirname(__FILE__) . '/' . implode('/', $parts) . '.php'; | |
if (file_exists($filename)) { | |
require_once $filename; | |
$foo = new $formName; | |
if (method_exists($foo, 'buildForm')) { | |
$foo->buildForm($form); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment