In Drupal 6 this was quite easy but with Rules-7.x some things have changed.

Idea by fago:

Wrap your data, inherit from EntityMetadataWrapper and create a custom wrapper class containing your custom save() method. It could be built very similar to the EntityDrupalWrapper (see entity API).

If we have that in place ... we just need to fix RulesState::isSavable() accordingly, e.g. we could introduce an interface or even provide your custom wrapper with Rules ...

This is the way to go! Yeah!

Comments

wizonesolutions’s picture

Version: 7.x-1.0 » 7.x-1.x-dev

Is this still in the plans? It seems like an event for "before a Webform submission is saved" is needed. If there is no explicit hook, you could just add a #submit handler to the relevant forms. Not sure how you'd react programmatically — maybe by implementing a query alter hook.

It'd be great to use Webform Rules as an enhanced version of the Conditionals tab in 4.x.

bisonbleu’s picture

Issue summary: View changes

Another way to achieve this without Rules is to create a custom module in which you implement hook_webform_submission_presave().

Here is the example from /sites/all/modules/webform/webform.api.php:

/**
 * Modify a Webform submission, prior to saving it in the database.
 *
 * @param $node
 *   The Webform node on which this submission was made.
 * @param $submission
 *   The Webform submission that is about to be saved to the database.
 */
function hook_webform_submission_presave($node, &$submission) {
  // Update some component's value before it is saved.
  $component_id = 4;
  $submission->data[$component_id][0] = 'foo';
}