You are here

function acquia_contenthub_subscriber_process_filters in Acquia Content Hub 8

Processes an Asset that has arrived through a Webhook.

Parameters

\Drupal\acquia_contenthub\ImportEntityManager $import_entity_manager: The Import Entity Service.

\Drupal\acquia_contenthub_subscriber\Entity\ContentHubFilter[] $contenthub_filters: of Content Hub Filters. Array of Content Hub Filters.

array $asset: The asset to process.

1 call to acquia_contenthub_subscriber_process_filters()
acquia_contenthub_subscriber_acquia_contenthub_process_webhook_alter in acquia_contenthub_subscriber/acquia_contenthub_subscriber.module
Implements hook_acquia_contenthub_process_webhook_alter().

File

acquia_contenthub_subscriber/acquia_contenthub_subscriber.module, line 81
Handles Content Hub Content Subscriptions and Updates.

Code

function acquia_contenthub_subscriber_process_filters(ImportEntityManager $import_entity_manager, array $contenthub_filters, array $asset) {
  foreach ($contenthub_filters as $contenthub_filter) {

    // Get the Status from the Filter Information.
    $status = $contenthub_filter
      ->getPublishStatus();

    // If Publish Status is FALSE, stop processing this filter and jump to the
    // next one.
    if ($status === FALSE) {
      continue;
    }

    // Evaluate filter conditions to see if it matches for this entity.
    if (acquia_contenthub_subscriber_evaluate_filter_conditions($contenthub_filter, $asset)) {

      // Assign the appropriate author for this filter (User UUID).
      $uid = $contenthub_filter->author;
      $user = User::load($uid);

      // If Filter condition evaluates to TRUE, save entity with dependencies.
      $import_entity_manager
        ->import($asset['uuid'], TRUE, $user
        ->uuid(), $status);

      // If this filter matches, then stop processing other filters.
      // @TODO: Find a better way of handling different filters (ie. priority).
      break;
    }
  }
}