You are here

public function ContentHubSubscription::registerWebhook in Acquia Content Hub 8

Registers a Webhook to Content Hub.

Note that this method only sends the request to register a webhook but it is also required for this endpoint ($webhook_url) to provide an appropriate response to Content Hub when it tries to verify the authenticity of the registration request.

Parameters

string $webhook_url: The webhook URL.

Return value

bool TRUE if successful registration, FALSE otherwise.

File

src/ContentHubSubscription.php, line 292

Class

ContentHubSubscription
Handles operations on the Acquia Content Hub Subscription.

Namespace

Drupal\acquia_contenthub

Code

public function registerWebhook($webhook_url) {
  $success = FALSE;
  if ($webhook = $this->clientManager
    ->createRequest('addWebhook', [
    $webhook_url,
  ])) {
    $this->config
      ->set('webhook_uuid', $webhook['uuid']);
    $this->config
      ->set('webhook_url', $webhook['url']);
    $this->config
      ->save();
    \Drupal::messenger()
      ->addStatus($this
      ->t('Webhooks have been enabled. This site will now receive updates from Content Hub.'));
    $success = TRUE;
    $message = new FormattableMarkup('Successful registration of Webhook URL = @URL', [
      '@URL' => $webhook['url'],
    ]);
    $this->loggerFactory
      ->get('acquia_contenthub')
      ->debug($message);
  }
  return $success;
}