Skip to content

Instantly share code, notes, and snippets.

@jec006
Created July 5, 2012 19:10
Show Gist options
  • Save jec006/3055759 to your computer and use it in GitHub Desktop.
Save jec006/3055759 to your computer and use it in GitHub Desktop.
The manager getForm function
<?php
/**
* Passthrough from Drupal form to the correct condition for building the preview form
*
* @param $form
* The form array used in hook_form
* @param $form_state
* The form_state array as used in hook_form
*
* @return
* A drupal form array created but the root condition
*/
public function getPreviewForm() {
$root_condition = $this->getRootCondition();
$getForm = function($form, &$form_state) {
return $root_condition->getElement($form, $form_state);
}
drupal_get_form('sps_condition_preview_form', $getForm);
}
<?php
/**
* A form callback for use by drupal_get_form().
*
* When called like:
* drupal_get_form('sps_condition_preview_form', array($this, 'getPreviewForm'))
* by the manager or a condition, it will return that form.
*
* @return
* A FAPI array for drupal_get_form if a callback is provided, or NULL
*
* @see Manager::getPreviewForm();
*/
function sps_condition_preview_form($form, &$form_state) {
if (!empty($form_state['build_info']['args'][0])) {
$form_function = $form_state['build_info']['args'][0];
if(is_callable($form_function)) {
$form_function($form, $form_state);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment