Skip to content

Instantly share code, notes, and snippets.

@mlutfy
Created February 6, 2017 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlutfy/106a73dc93b06bae9e0a3de0920a10e4 to your computer and use it in GitHub Desktop.
Save mlutfy/106a73dc93b06bae9e0a3de0920a10e4 to your computer and use it in GitHub Desktop.
/**
* 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