public function PreviewEntity::onHandleWebhook in Acquia Content Hub 8.2
Handles webhook events.
Parameters
\Drupal\acquia_contenthub\Event\HandleWebhookEvent $event: The HandleWebhookEvent object.
Throws
\Exception
File
- modules/
acquia_contenthub_preview/ src/ EventSubscriber/ HandleWebhook/ PreviewEntity.php, line 62
Class
- PreviewEntity
- Previews entities across content as a service sites.
Namespace
Drupal\acquia_contenthub_preview\EventSubscriber\HandleWebhookCode
public function onHandleWebhook(HandleWebhookEvent $event) : void {
$payload = $event
->getPayload();
$client = $event
->getClient();
$settings = $client
->getSettings();
$client_uuid = $settings
->getUuid();
if ('successful' !== $payload['status'] || empty($payload['preview']) || 'preview' !== $payload['crud'] || $payload['initiator'] === $client_uuid || empty($payload['cdf'])) {
return;
}
$cdf = $payload['cdf']['entities'];
$document = new CDFDocument();
foreach ($cdf as $object) {
$cdfObject = CDFObject::fromArray($object);
$document
->addCdfEntity($cdfObject);
}
$this->common
->importEntityCdfDocument($document);
$url = Url::fromRoute('acquia_contenthub_preview.preview', [
'uuid' => $payload['preview'],
], [
'absolute' => TRUE,
'base_url' => $event
->getRequest()
->getSchemeAndHttpHost(),
]);
$response = $this
->getResponse($event, '<iframe src="' . $url
->toString() . '" width="1165" height="500"></iframe>');
$event
->setResponse($response);
$event
->stopPropagation();
}