acquia_contenthub_subscriber.module in Acquia Content Hub 8.2
Drupal Module: Acquia Content Hub - Subscriber.
Subscriber imports content from Content Hub services to your Drupal site.
File
modules/acquia_contenthub_subscriber/acquia_contenthub_subscriber.moduleView source
<?php
/**
* @file
* Drupal Module: Acquia Content Hub - Subscriber.
*
* Subscriber imports content from Content Hub services to your Drupal site.
*/
use Acquia\ContentHubClient\ContentHubClient;
use Drupal\Core\Entity\EntityInterface;
/**
* Implements hook_entity_delete().
*
* @throws \Exception
*/
function acquia_contenthub_subscriber_entity_delete(EntityInterface $entity) {
/** @var \Drupal\acquia_contenthub\Client\ClientFactory $factory */
$factory = \Drupal::service('acquia_contenthub.client.factory');
$client = $factory
->getClient();
if ($client) {
_acquia_contenthub_subscriber_delete_entity($entity, $client);
}
}
/**
* Implements hook_entity_insert().
*/
function acquia_contenthub_subscriber_entity_insert(EntityInterface $entity) {
\Drupal::service('acquia_contenthub.stub.tracker')
->track($entity);
}
/**
* Delete subscriber entities from the interest list and tracking table.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to remove.
* @param \Acquia\ContentHubClient\ContentHubClient $client
* The client connection to the ContentHub service.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
function _acquia_contenthub_subscriber_delete_entity(EntityInterface $entity, ContentHubClient $client) {
$uuid = $entity
->uuid();
/** @var \Drupal\acquia_contenthub_subscriber\SubscriberTracker $tracker */
$tracker = \Drupal::service('acquia_contenthub_subscriber.tracker');
if ($uuid && $tracker
->isTracked($uuid)) {
$tracker
->delete($uuid);
\Drupal::logger('acquia_contenthub_subscriber')
->info(sprintf("Removed tracking for entity with UUID = \"%s\".", $uuid));
// Clean up the interest list.
$config = \Drupal::config('acquia_contenthub.admin_settings');
if (!($config
->get('send_contenthub_updates') ?? TRUE)) {
return;
}
$settings = $client
->getSettings();
$webhook_uuid = $settings
->getWebhook('uuid');
$client
->deleteInterest($uuid, $webhook_uuid);
\Drupal::logger('acquia_contenthub_subscriber')
->info(sprintf("Deleted entity with UUID = \"%s\" from webhook's interest list.", $uuid));
}
}
Functions
Name | Description |
---|---|
acquia_contenthub_subscriber_entity_delete | Implements hook_entity_delete(). |
acquia_contenthub_subscriber_entity_insert | Implements hook_entity_insert(). |
_acquia_contenthub_subscriber_delete_entity | Delete subscriber entities from the interest list and tracking table. |