'. t('Settings and overview of form events.') .'
'; } } /** * Implementation of hook_menu(). */ function rules_forms_menu() { $items = array(); $items[RULES_ADMIN_FORMS_PATH] = array( 'title' => 'Form events', 'description' => 'Configure Rules forms events.', 'page callback' => 'drupal_get_form', 'page arguments' => array('rules_forms_admin_events'), 'access arguments' => array('administer rules'), 'type' => MENU_NORMAL_ITEM, 'weight' => 6, 'file' => 'rules_forms.admin.inc', ); $items[RULES_ADMIN_FORMS_PATH .'/%/activate'] = array( 'title' => 'Activate events for a form', 'type' => MENU_CALLBACK, 'page callback' => 'rules_forms_activate', 'page arguments' => array(3), 'access arguments' => array('administer rules'), 'file' => 'rules_forms.admin.inc', ); return $items; } /** * Implementation of hook_form_alter(). */ function rules_forms_form_alter(&$form, &$form_state, $form_id) { $form_events = variable_get('rules_forms_events', array()); // Invoke event if form is enabled if (isset($form_events[$form_id])) { rules_forms_invoke_event('form_built', $form, $form_state, $form_id); $form['#after_build'][] = 'rules_forms_after_build'; if (!empty($_SESSION['rules_forms_element_ids'])) { rules_forms_add_element_id($form); } } // Display form ID message if enabled for this session. if (!empty($_SESSION['rules_forms_message'])) { $link = l($form_id, RULES_ADMIN_FORMS_PATH .'/'. $form_id .'/activate/'); $msg = t('Activate events for '); drupal_set_message($msg . $link, 'status', FALSE); } } /** * Submit handler to invoke "form submitted" events */ function rules_forms_event_submit(&$form, &$form_state) { rules_forms_invoke_event('form_submit', $form, $form_state); } /** * Validation handler to invoke "form validate" events */ function rules_forms_event_validate(&$form, &$form_state) { rules_forms_invoke_event('form_validate', $form, $form_state); } /** * Invoke rules event of a certain type. */ function rules_forms_invoke_event($event_type, &$form, &$form_state, $form_id = NULL) { if (empty($form_id)) { $form_id = $form['form_id']['#value']; } $action_args = array( 'form' => &$form, 'form_state' => &$form_state, 'form_id' => $form_id, ); rules_invoke_event($form_id .'_'. $event_type, $action_args); } /** * Add element IDs as prefix/suffix code to all form elements. */ function rules_forms_add_element_id(&$form, $parent = '') { $bracket = ($parent === '') ? '' : ']'; foreach (element_children($form) as $key) { if (isset($form[$key]['#type'])) { if ($form[$key]['#type'] === 'hidden' || $form[$key]['#type'] === 'token') { $element_id = '