You are here

public function WebformSubmissionHandler::onUnserializeWebformElements in Acquia Content Hub 8.2

Unserialize webform elements from webform submission CDF.

Parameters

\Drupal\acquia_contenthub\Event\UnserializeAdditionalMetadataEvent $event: Unserialize event for additional metadata.

File

src/EventSubscriber/Cdf/WebformSubmissionHandler.php, line 64

Class

WebformSubmissionHandler
The Webform submission entity handler.

Namespace

Drupal\acquia_contenthub\EventSubscriber\Cdf

Code

public function onUnserializeWebformElements(UnserializeAdditionalMetadataEvent $event) {
  $cdf = $event
    ->getCdf();

  // Bail early if this isn't a webform submission entity.
  if ($cdf
    ->getAttribute('entity_type')
    ->getValue()['und'] !== 'webform_submission') {
    return;
  }

  /** @var \Drupal\webform\WebformSubmissionInterface $entity */
  $entity = $event
    ->getEntity();
  $metadata = $cdf
    ->getMetadata();

  // Get webform elements data.
  $webform_elements = json_decode(base64_decode($metadata['additional_data']['webform_elements']), TRUE);
  if (is_array($webform_elements)) {
    $entity
      ->setData($webform_elements);
    $event
      ->setEntity($entity);
  }
  $event
    ->stopPropagation();
}