Created
July 11, 2012 19:04
-
-
Save jec006/3092403 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
<?php | |
/** | |
* Implements ConditionInterface::getElement(). | |
* | |
* Gets the form for the condition. | |
* | |
* @see sps_condition_form_validate_callback | |
* @see sps_condition_form_submit_callback | |
*/ | |
public function getElement($element, &$form_state) { | |
$sub_state = $form_state; | |
$sub_state['values'] = isset($form_state['values']['widget']) ? $form_state['values']['widget'] : array(); | |
$element['widget'] = $this->widget->getPreviewForm(array(), $sub_state); | |
$element['widget']['#tree'] = TRUE; | |
$element['preview'] = array( | |
'#type' => 'submit', | |
'#value' => 'Preview', | |
); | |
$element['#sps_validate'] = array($this, 'validateElement'); | |
$element['#validate'] = 'sps_condition_form_validate_callback'; | |
$element['#sps_submit'] = array($this, 'submitElement'); | |
$element['#submit'] = 'sps_condition_form_submit_callback'; | |
return $element; | |
} |
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
<?php | |
/** | |
* A validate callback for forms which will subsequently call the forms | |
* #sps_validate function. | |
* | |
* This allows us to call class methods as form validators. To use #sps_validate, | |
* should be set to a callable item, and #submit set to this function. | |
*/ | |
function sps_condition_form_validate_callback($form, &$form_state) { | |
if (!empty($form['#sps_validate']) && is_callable($form['#sps_validate'])) { | |
$form['#sps_validate']($form, $form_state); | |
} | |
} | |
/** | |
* A submit callback for forms which will subsequently call the forms | |
* #sps_submit function. | |
* | |
* This allows us to call class methods as form submitters. To use #sps_submit, | |
* should be set to a callable item, and #submit set to this function. | |
*/ | |
function sps_condition_form_submit_callback($form, &$form_state) { | |
if (!empty($form['#sps_submit']) && is_callable($form['#sps_submit'])) { | |
$form['#sps_submit']($form, $form_state); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment