Skip to content
Snippets Groups Projects
Commit 5f2af42d authored by Stefan Borchert's avatar Stefan Borchert
Browse files

Changes for 7.x release. Adding new event for triggering 'Save as draft'.

parent 019baba3
No related branches found
No related tags found
No related merge requests found
; $Id$
name = Webform Rules
core = 6.x
core = 7.x
description = "Adds rules integration for webform submissions."
package = Webform
files[] = webform_rules.module
files[] = webform_rules.rules.inc
dependencies[] = webform
dependencies[] = rules
......@@ -7,7 +7,7 @@
*/
/**
* Implementation of hook_form_alter().
* Implements of hook_form_alter().
*/
function webform_rules_form_alter(&$form, $form_state, $form_id) {
if (strpos($form_id, 'webform_client_form_') !== FALSE) {
......@@ -21,10 +21,24 @@ function webform_rules_form_alter(&$form, $form_state, $form_id) {
*/
function webform_rules_client_form_submit($form, &$form_state) {
global $user;
// Check if user is submitting as a draft.
$is_draft = $form_state['values']['op'] == t('Save Draft');
// Get webform node.
$node = isset($form['#node']) ? $form['#node'] : new stdClass();
$node = $form['#node'];
// Get submitted data from webform.
$data = isset($form['#post']['submitted']) ? $form['#post']['submitted'] : array();
$submission_data = webform_submission_data($node, $form_state['values']['submitted']);
$data = array();
// Map values to field names.
foreach ($submission_data as $cid => $value) {
$component = $node->webform['components'][$cid];
$data[$component['form_key']]['name'] = $component['name'];
$data[$component['form_key']]['value'] = $value['value'];
}
// Invoke the rules event.
rules_invoke_event('webform_rules_submit', $user, $node, $data);
if ($is_draft) {
rules_invoke_event('webform_rules_submit_as_draft', $user, $node, $data);
}
else {
rules_invoke_event('webform_rules_submit', $user, $node, $data);
}
}
......@@ -7,28 +7,43 @@
*/
/**
* Implementation of hook_rules_event_info().
* Implements of hook_rules_event_info().
* @ingroup rules
*/
function webform_rules_rules_event_info() {
return array(
'webform_rules_submit_as_draft' => array(
'label' => t('After a webform has been saved as draft'),
'group' => t('Webform'),
'variables' => _webform_rules_event_variables(),
),
'webform_rules_submit' => array(
'label' => t('After a webform has been submitted'),
'module' => 'Webform',
'arguments' => array(
'user' => array(
'type' => 'user',
'label' => t('User, who submitted the webform'),
),
'node' => array(
'type' => 'node',
'label' => t('The webform node'),
),
'data' => array(
'type' => 'data',
'label' => t('The submitted webform data'),
),
),
'group' => t('Webform'),
'variables' => _webform_rules_event_variables(),
),
);
}
/**
* Helper function for event variables.
*
* @return
* All available variables for the rules events provided by webform_rules.
*/
function _webform_rules_event_variables() {
return array(
'user' => array(
'type' => 'user',
'label' => t('User, who submitted the webform'),
),
'node' => array(
'type' => 'node',
'label' => t('The webform node'),
),
'data' => array(
'type' => 'data',
'label' => t('The submitted webform data'),
),
);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment