You are here

function rules_forms_event_build in Rules Forms Support 7

Same name and namespace in other branches
  1. 7.2 rules_forms.module \rules_forms_event_build()

Form build handler. Stores form values and invokes the event.

3 calls to rules_forms_event_build()
RulesFormsAPITestCase::testEventBuild in ./rules_forms.test
Tests rules_forms_event_build().
RulesFormsConditionsTestCase::testElementValueChangedCondition in ./rules_forms.test
Tests callback for Condition: Element value has changed.
rules_forms_form_alter in ./rules_forms.module
Implements hook_form_alter().

File

./rules_forms.module, line 103
Rules Forms Support provides events, conditions, and actions for site forms.

Code

function rules_forms_event_build(&$form, &$form_state, $form_id, $entity, $entity_type) {

  // Save form element values for use in conditions.
  $form_state['rules_forms']['form_values'] = array();
  $form_info = rules_forms_get_form_info($form_id);
  if (isset($form_info['elements'])) {
    $form_values = array();
    foreach ($form_info['elements'] as $element_id => $info) {
      $element = _rules_forms_get_element($form, $element_id);
      if (isset($element['#value'])) {
        $form_values[$element_id] = $element['#value'];
      }
      elseif (isset($element['#default_value'])) {
        $form_values[$element_id] = $element['#default_value'];
      }
      else {
        $form_values[$element_id] = NULL;
      }
    }
    $form_state['rules_forms']['form_values'] = $form_values;
  }

  // Invoke the form_built event.
  rules_forms_invoke_event('form_built', $form, $form_state, $form_id, $entity, $entity_type);
}