You are here

function hook_acquia_contenthub_drupal_from_cdf_alter in Acquia Content Hub 8

Allow modules to modify the Drupal Entity after conversion from CDF.

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

This is useful to modify the Drupal Entity that came out as a result of its conversion from CDF fetched from Content Hub 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

string $entity_type_id: The Drupal Entity type ID.

object $entity: The Drupal entity.

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

File

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

Code

function hook_acquia_contenthub_drupal_from_cdf_alter($entity_type_id, $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 drupal entity after it has been denormalized
  // from the Content Hub CDF.
  if ($entity_type_id === 'node') {

    // Site String.
    $site_string = ' - From My Cool Site';

    // Obtain the title from the node entity.
    $title = $entity
      ->get('title')
      ->getValue();

    // 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[0]['value'], $site_string) === FALSE) {

      // Add the site string to the title.
      $title[0]['value'] .= $site_string;
      $entity
        ->get('title')
        ->setValue($title);
    }
  }
}