public function __construct($node, $submission) { $this->submission = $submission; $this->node = $node; $this->webform = new Webform($node); $this->submitted = $submission->submitted; $this->remote_addr = $submission->remote_addr; $this->data = array(); if (!isset($submission->tracking)) { $submission->tracking = (object) array(); if (\Drupal::moduleHandler()->moduleExists('webform_tracking') && isset($submission->sid)) { webform_tracking_load($submission); } } // 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); } } }
public function testComponent_ReturnsNULLForUnknownComponent() { $node = self::nodeStub(); $webform = new Webform($node); $this->assertNull($webform->component(12)); }