You are here

private function RulesWebformEventBase::initializeWebformInfo in RULES WEBFORM 3.x

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

Add data about webform to the 'webform_info' context variable.

(data such as name, date and others).

1 call to RulesWebformEventBase::initializeWebformInfo()
RulesWebformEventBase::__construct in src/Event/RulesWebformEventBase.php
Сonstructs the object.

File

src/Event/RulesWebformEventBase.php, line 130

Class

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

Namespace

Drupal\rules_webform\Event

Code

private function initializeWebformInfo(WebformSubmission $submission) {

  // The submission object needed for "Delete webform submission" action.
  // It is not added to the property definitions of webform_info and
  // therefore is not visible in autocomplete.
  $this->webform_info['submission'] = $submission;

  // Adding properties for which was created properties definitions
  // and which are visible in autocomplete.
  $this->webform_info['id'] = $submission
    ->getWebform()
    ->id();
  $this->webform_info['title'] = $submission
    ->getWebform()
    ->get('title');
  $this->webform_info['submitter_id'] = $submission
    ->getOwnerId();
  $this->webform_info['submitter_name'] = $submission
    ->getOwner()
    ->getDisplayName();
  $this->webform_info['submitter_email'] = $submission
    ->getOwner()
    ->getEmail();
  $timestamp = $submission
    ->getcreatedTime();
  $this->webform_info['created']['timestamp'] = $timestamp;
  $this->webform_info['created']['date_short'] = \Drupal::service('date.formatter')
    ->format($timestamp, 'date_short');
  $this->webform_info['created']['date_medium'] = \Drupal::service('date.formatter')
    ->format($timestamp, 'date_medium');
  $this->webform_info['created']['date_long'] = \Drupal::service('date.formatter')
    ->format($timestamp, 'date_long');
  $this->webform_info['created']['html_datetime'] = \Drupal::service('date.formatter')
    ->format($timestamp, 'html_datetime');
  $this->webform_info['created']['html_date'] = \Drupal::service('date.formatter')
    ->format($timestamp, 'html_date');
  $this->webform_info['created']['html_time'] = \Drupal::service('date.formatter')
    ->format($timestamp, 'html_time');
  $timestamp = $submission
    ->getchangedTime();
  $this->webform_info['changed']['timestamp'] = $timestamp;
  $this->webform_info['changed']['date_short'] = \Drupal::service('date.formatter')
    ->format($timestamp, 'date_short');
  $this->webform_info['changed']['date_medium'] = \Drupal::service('date.formatter')
    ->format($timestamp, 'date_medium');
  $this->webform_info['changed']['date_long'] = \Drupal::service('date.formatter')
    ->format($timestamp, 'date_long');
  $this->webform_info['changed']['html_datetime'] = \Drupal::service('date.formatter')
    ->format($timestamp, 'html_datetime');
  $this->webform_info['changed']['html_date'] = \Drupal::service('date.formatter')
    ->format($timestamp, 'html_date');
  $this->webform_info['changed']['html_time'] = \Drupal::service('date.formatter')
    ->format($timestamp, 'html_time');
  if ($submission
    ->isDraft()) {

    // To prevent an error message if a user will try to use 'completed'
    // values when a draft was submitted.
    $this->webform_info['completed']['timestamp'] = '';
    $this->webform_info['completed']['date_short'] = '';
    $this->webform_info['completed']['date_medium'] = '';
    $this->webform_info['completed']['date_long'] = '';
    $this->webform_info['completed']['html_datetime'] = '';
    $this->webform_info['completed']['html_date'] = '';
    $this->webform_info['completed']['html_time'] = '';
  }
  else {
    $timestamp = $submission
      ->getcompletedTime();
    $this->webform_info['completed']['timestamp'] = $timestamp;
    $this->webform_info['completed']['date_short'] = \Drupal::service('date.formatter')
      ->format($timestamp, 'date_short');
    $this->webform_info['completed']['date_medium'] = \Drupal::service('date.formatter')
      ->format($timestamp, 'date_medium');
    $this->webform_info['completed']['date_long'] = \Drupal::service('date.formatter')
      ->format($timestamp, 'date_long');
    $this->webform_info['completed']['html_datetime'] = \Drupal::service('date.formatter')
      ->format($timestamp, 'html_datetime');
    $this->webform_info['completed']['html_date'] = \Drupal::service('date.formatter')
      ->format($timestamp, 'html_date');
    $this->webform_info['completed']['html_time'] = \Drupal::service('date.formatter')
      ->format($timestamp, 'html_time');
  }
  $this->webform_info['number'] = $submission
    ->serial();
  $this->webform_info['id_submission'] = $submission
    ->id();
  $this->webform_info['uuid'] = $submission
    ->uuid();
  $this->webform_info['uri'] = $submission
    ->get('uri')->value;
  $this->webform_info['ip'] = $submission
    ->getRemoteAddr();
  $this->webform_info['language'] = $submission
    ->language()
    ->getName();
  $this->webform_info['is_draft'] = $submission
    ->isDraft();
  $this->webform_info['current_page'] = $submission
    ->getcurrentPage();
}