function rules_webform_add_action_delete_webform_submission in RULES WEBFORM 8
Same name and namespace in other branches
- 3.x rules_webform.module \rules_webform_add_action_delete_webform_submission()
Adding 'Delete webform submission' action if a user selected it.
1 string reference to 'rules_webform_add_action_delete_webform_submission'
- rules_webform_form_rules_expression_edit_validate in ./
rules_webform.module - Adding submit handler for adding rule actions.
File
- ./
rules_webform.module, line 330 - Contains rules_webform.module.
Code
function rules_webform_add_action_delete_webform_submission($form, FormStateInterface $form_state) {
$values = [];
$values['context_mapping']['webform_info'] = 'webform_info';
$values['provides_mapping'] = [];
$values['action_id'] = 'delete_webform_submission';
$values['negate'] = 0;
$config = ContextConfig::create($values);
$reaction_rule = \Drupal::request()
->get('rules_reaction_rule');
$component = $reaction_rule
->getComponent();
// Check if this action was already added then don't add it again.
$actions = $component
->getExpression()
->getActions()
->getConfiguration()['actions'];
foreach ($actions as $action) {
if ($action['action_id'] == 'delete_webform_submission') {
$form_state
->setRedirect('entity.rules_reaction_rule.edit_form', [
'rules_reaction_rule' => $reaction_rule->id,
]);
return;
}
}
$component
->getExpression()
->addAction('delete_webform_submission', $config);
$reaction_rule
->updateFromComponent($component);
$reaction_rule
->save();
$form_state
->setRedirect('entity.rules_reaction_rule.edit_form', [
'rules_reaction_rule' => $reaction_rule->id,
]);
}