You are here

public function Submission::__construct in Little helpers 7

Same name and namespace in other branches
  1. 7.2 src/Webform/Submission.php \Drupal\little_helpers\Webform\Submission::__construct()

Constructor.

Parameters

object $node_or_webform: Either a node-object or a Webform instance.

object $submission: A submission object as created by webform.

1 call to Submission::__construct()
Submission::__wakeup in src/Webform/Submission.php

File

src/Webform/Submission.php, line 51

Class

Submission
A useful wrapper for webform submission objects.

Namespace

Drupal\little_helpers\Webform

Code

public function __construct($node_or_webform, $submission) {
  $this->submission = $submission;
  if ($node_or_webform instanceof Webform) {
    $this->node = $node_or_webform->node;
    $this->webform = $node_or_webform;
  }
  else {
    $this->node = $node_or_webform;
    $this->webform = new Webform($node_or_webform);
  }
  $this->data = array();
  if (!isset($submission->tracking)) {
    $submission->tracking = (object) [];
  }

  // Some components like checkboxes and fieldsets may have no values
  // We want to return NULL in that case instead of throwing a notice.
  $webform4 = Webform::is_webform4();
  foreach (array_keys($this->node->webform['components']) as $cid) {
    if (isset($this->submission->data[$cid])) {
      $this->data[$cid] = $webform4 ? $this->submission->data[$cid] : $this->submission->data[$cid]['value'];
    }
    else {
      $this->data[$cid] = array(
        NULL,
      );
    }
  }
}