You are here

function hook_acquia_contenthub_cdf_from_hub_alter in Acquia Content Hub 8

Allows modules to modify the CDF before converting to Drupal Entity.

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

This is useful to modify the CDF that has been fetched from the Content Hub before it has been converted to Drupal Entity during the denormalization process. Note that we these changes affect the local entity imported from Content Hub but do not affect the entity in Content Hub itself.

Parameters

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

1 invocation of hook_acquia_contenthub_cdf_from_hub_alter()
ContentEntityCdfNormalizer::denormalize in src/Normalizer/ContentEntityCdfNormalizer.php
Denormalizes data back into an object of the given class.

File

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

Code

function hook_acquia_contenthub_cdf_from_hub_alter(ContentHubEntity $contenthub_entity) {

  // The following example modifies the title of the node for all nodes
  // imported from Content Hub and adds the string ' - From My Cool Site'.
  // It does it by changing the CDF before denormalizing to a drupal entity.
  if ($contenthub_entity
    ->getType() == 'node') {

    // Site String.
    $site_string = ' - From My Cool Site';
    $title = $contenthub_entity
      ->getAttribute('title');
    $language = array_keys($title['value']);
    $language = reset($language);

    // Always check that the changes have already been applied, because the
    // denormalizer could be called more than once during the import process.
    if (strpos($title['value'][$language], $site_string) === FALSE) {

      // Add site string to the title.
      $title['value'][$language] = $title['value'][$language] . $site_string;
      $contenthub_entity['attributes']['title'] = $title;
    }
  }
}