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

Backporting from 7.x branch. New event for saving a webform as draft.

parent 019baba3
No related branches found
Tags 7.x-1.11
No related merge requests found
......@@ -14,7 +14,7 @@ You need the following modules for a working feature:
-- INSTALLATION --
Copy the module files to you module directory and then enable it on the admin
modules page. After that you'll see a new event in the listing while creating
modules page. After that you'll see two new events in the listing while creating
a new rule.
......
......@@ -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);
}
}
......@@ -12,23 +12,38 @@
*/
function webform_rules_rules_event_info() {
return array(
'webform_rules_submit_as_draft' => array(
'label' => t('After a webform has been saved as draft'),
'module' => t('Webform'),
'arguments' => _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'),
),
),
'module' => t('Webform'),
'arguments' => _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