You are here

protected function ContentHubConnectionManager::createDefaultFilter in Acquia Content Hub 8.2

Creates default filter for the site.

Parameters

string $filter_name: The name of the filter.

Return value

array The response of the attempt.

Throws

\Exception

1 call to ContentHubConnectionManager::createDefaultFilter()
ContentHubConnectionManager::addDefaultFilterToWebhook in src/ContentHubConnectionManager.php
Adds default filter to a Webhook.

File

src/ContentHubConnectionManager.php, line 380

Class

ContentHubConnectionManager
Responsible for connection management actions.

Namespace

Drupal\acquia_contenthub

Code

protected function createDefaultFilter(string $filter_name) {
  $this
    ->initialize();
  $filter = $this->client
    ->getFilterByName($filter_name);

  // Only create default filter if it does not exist yet for the current
  // client.
  if (empty($filter['uuid'])) {
    $site_origin = $this->client
      ->getSettings()
      ->getUuid();
    $filter_query = [
      'bool' => [
        'should' => [
          [
            'match' => [
              'data.attributes.channels.value.und' => $site_origin,
            ],
          ],
          [
            'match' => [
              'data.origin' => $site_origin,
            ],
          ],
        ],
      ],
    ];
    $filter = $this->client
      ->putFilter($filter_query, $filter_name);
  }
  return $filter;
}