protected function AcquiaContentHubFiltersCommands::reduceFilterByWebhook in Acquia Content Hub 8.2
Returns filters related to specified webhook.
Parameters
array $filters: Cloud filters list.
\Acquia\ContentHubClient\Webhook[] $webhooks: All available webhooks list.
string|null $webhook: Webhook URL.
Return value
array Webhooks filtered.
1 call to AcquiaContentHubFiltersCommands::reduceFilterByWebhook()
- AcquiaContentHubFiltersCommands::buildCloudFiltersList in src/
Commands/ AcquiaContentHubFiltersCommands.php - Builds cloud filters list.
File
- src/
Commands/ AcquiaContentHubFiltersCommands.php, line 283
Class
- AcquiaContentHubFiltersCommands
- Drush command to interact with Acquia Content Hub filters.
Namespace
Drupal\acquia_contenthub\CommandsCode
protected function reduceFilterByWebhook(array $filters, array $webhooks, ?string $webhook) : array {
if (empty($webhook)) {
return $filters;
}
// Build a map of webhook => filters.
$map = [];
foreach ($webhooks as $wh) {
$map[$wh
->getUrl()] = $wh
->getFilters();
}
if (empty($map[$webhook]) || !is_array($map[$webhook])) {
return [];
}
$ids = $map[$webhook];
$reducer = function ($carry, $item) use ($ids) {
if (in_array($item['uuid'], $ids, TRUE)) {
$carry[] = $item;
}
return $carry;
};
return array_reduce($filters, $reducer, []);
}