You are here

public function RulesWebformEventBase::__construct in RULES WEBFORM 3.x

Same name and namespace in other branches
  1. 8 src/Event/RulesWebformEventBase.php \Drupal\rules_webform\Event\RulesWebformEventBase::__construct()

Сonstructs the object.

Rewrite the information needed for 'webform_fields' properties definitions. This allows to create rules for several different webforms. The information are then using in 'WebformFieldsDataDefinition' class and in the 'WebformFieldsUnchangedDataDefinition' class. And it's needed for properly working of property selector of 'webform_fields' and 'webform_fields_unchanged' context variables.

Parameters

Drupal\webform\Entity\WebformSubmission $submission: Webform submission object.

File

src/Event/RulesWebformEventBase.php, line 52

Class

RulesWebformEventBase
Base class for events available in the 'RULES WEBFORM' module.

Namespace

Drupal\rules_webform\Event

Code

public function __construct(WebformSubmission $submission) {

  // Store webform submission for using in 'set_webform_field' action.
  \Drupal::state()
    ->set('rules_webform.submission', $submission);

  // Get the information about a webform fields.
  $webform = Webform::load($submission
    ->getWebform()
    ->id());
  $elements = $webform
    ->getElementsInitializedAndFlattened();
  $fields_definitions = [];
  $this
    ->extractcompositeElements($elements, $fields_definitions);

  // Store webform fields information for using in the
  // 'WebformFieldsDataDefinition' class
  // and in the 'WebformFieldsUnchangedDataDefinition' class.
  \Drupal::state()
    ->set('rules_webform.fields_definitions', $fields_definitions);

  // Add properties data to the 'webform_info' context variable.
  $this
    ->initializeWebformInfo($submission);
  $this->webform_fields = $this
    ->extractcompositeSubmissionData($submission
    ->getData());
  $this->webform_fields_unchanged = $this
    ->extractcompositeSubmissionData($submission
    ->getOriginalData());
}