You are here

function rules_webform_add_condition in RULES WEBFORM 8

Same name and namespace in other branches
  1. 3.x rules_webform.module \rules_webform_add_condition()

Add rule condition 'webform_name' based on selected webform id.

1 call to rules_webform_add_condition()
rules_webform_check_if_webform_submit_event_selected in ./rules_webform.module
Check if Webform events selected.

File

./rules_webform.module, line 101
Contains rules_webform.module.

Code

function rules_webform_add_condition($form, FormStateInterface $form_state) {
  $selected_webform_id = $form_state
    ->getValue('webform_id');
  $values = [];
  $values['context_values'] = [
    'selected_webform_id' => $selected_webform_id,
  ];

  // Submitted webform ID will be extracted from webform_info context variable.
  // And then will be using for compare selected and submitted webform
  // in 'webform_name' condition.
  $values['context_mapping']['submitted_webform_info'] = 'webform_info';
  $values['provides_mapping'] = [];
  $values['condition_id'] = 'webform_name';
  $values['negate'] = 0;
  $config = ContextConfig::create($values);
  $entity = $form_state
    ->getFormObject()
    ->getEntity();
  $component = $entity
    ->getComponent();
  $component
    ->getExpression()
    ->addCondition('webform_name', $config);
  $entity
    ->updateFromComponent($component);
}