You are here

function hook_acquia_contenthub_cdf_from_drupal_alter in Acquia Content Hub 8

Allows modules to modify the CDF before it is sent to the Content Hub.

Common Data Format (CDF): https://docs.acquia.com/content-hub/cdf.

This is very useful to modify the CDF (usually its attributes) before it is sent to the Content Hub during the normalization process. Note that the changes will be reflected in the entity published in Content Hub, but the local Drupal entity will not be affected.

Parameters

\Acquia\ContentHubClient\Entity $contenthub_entity: The Content Hub CDF.

1 invocation of hook_acquia_contenthub_cdf_from_drupal_alter()
ContentEntityCdfNormalizer::normalize in src/Normalizer/ContentEntityCdfNormalizer.php
Normalizes an object into a set of arrays/scalars.

File

./acquia_contenthub.api.php, line 69
Hooks provided by the Acquia Content Hub module.

Code

function hook_acquia_contenthub_cdf_from_drupal_alter(ContentHubEntity $contenthub_entity) {

  // The following example modifies the title of the node for all nodes
  // exported to Content Hub and adds the string ' - By My Cool Site'.
  // It does it by modifying the title after producing the CDF that is fetched
  // by Content Hub.
  if ($contenthub_entity
    ->getType() == 'node') {

    // Site String.
    $site_string = ' - By My Cool Site';
    $title = $contenthub_entity
      ->getAttribute('title')
      ->getValues();
    $language = reset(array_keys($title));

    // Always check that the changes have already been applied, because the
    // normalizer could be called more than once during the export process.
    if (strpos($title[$language], $site_string) === FALSE) {
      $contenthub_entity
        ->getAttribute('title')
        ->setValue($title[$language] . $site_string, $language);

      // Remember, in the code above you are just adding text to the CDF that
      // comes from an existent drupal entity without saving changes to the
      // entity itself, then in order for these changes to be obtained from
      // Content Hub, you would need to invalidate the cache tag for this
      // particular node so the changes take effect.
    }
  }
}