Information for: DEVELOPERS   PARTNERS

Deleting content from subscribing sites

Whenever content is unpublished or deleted from your publishing website, you may want to also remove the content from your subscribing websites. To delete this content, create a small custom Drupal module. For information about creating custom modules in Drupal 8, see Creating custom modules on Drupal.org.

Content deletion code for Drupal 8

When content is unpublished or deleted from your publishing website, it is also removed from Content Hub. The Content Hub modules do not remove content on their own; content will remain on any subscriber websites that have previously imported it.

Use the following Drupal 8-based code in a custom module on the subscribing websites to instruct subscribers to delete their copies of the content:

function my_module_acquia_contenthub_process_webhook_alter($webhook) {
if($webhook['status'] == 'successful' && $webhook['crud'] == 'delete') {
   $entity_repository = \Drupal::service('entity.repository');
   foreach($webhook['assets'] as $asset) {
      $entity = $entity_repository->loadEntityByUuid($asset['type'], $asset['uuid']);
      if($entity) {
      $entity->delete();
      }
   }
}
}

Important

The DELETE webhook is sent to all subscriber websites. It affects content only in your subscribing websites that have this code deployed, whether or not automated updates are turned on. The entities will be deleted from your subscribing websites, even if they have been edited or changed.