You are here

public function GetFile::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_publisher/src/EventSubscriber/HandleWebhook/GetFile.php, line 65

Class

GetFile
Gets files during preview in content as a service.

Namespace

Drupal\acquia_contenthub_publisher\EventSubscriber\HandleWebhook

Code

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['uuid']) || 'getFile' !== $payload['crud'] || $payload['initiator'] === $client_uuid || empty($payload['cdf'])) {
    return;
  }
  $file_uri = $payload['cdf']['uri'];
  $file_scheme = $payload['cdf']['scheme'];
  if ($this->streamWrapperManager
    ->isValidScheme($file_scheme) && is_file($file_uri)) {
    $binary = new BinaryFileResponse($file_uri, 200, [], $file_scheme === 'private' ? FALSE : TRUE, 'inline');
    $response = $this
      ->getResponse($event, '', 200, $binary);
    $event
      ->setResponse($response);
    $event
      ->stopPropagation();
  }
}