You are here

protected function ContentEntityCdfNormalizer::excludedProperties in Acquia Content Hub 8

Provides a list of entity properties that will be excluded from the CDF.

When building the CDF entity for the Content Hub we are exporting Drupal entities that will be imported by other Drupal sites, so nids, tids, fids, etc. should not be transferred, as they will be different in different Drupal sites. We are relying in Drupal <uuid>'s as the entity identifier. So <uuid>'s will persist through the different sites. (We will need to verify this claim!)

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: The content entity.

Return value

array An array of excluded properties.

3 calls to ContentEntityCdfNormalizer::excludedProperties()
ContentEntityCdfNormalizer::addFieldsToContentHubEntity in src/Normalizer/ContentEntityCdfNormalizer.php
Get fields from given entity.
ContentEntityCdfNormalizer::addFieldsToDrupalEntity in src/Normalizer/ContentEntityCdfNormalizer.php
Adds Content Hub Data to Drupal Entity Fields.
ContentEntityCdfNormalizer::getReferencedFields in src/Normalizer/ContentEntityCdfNormalizer.php
Get entity reference fields.

File

src/Normalizer/ContentEntityCdfNormalizer.php, line 1095

Class

ContentEntityCdfNormalizer
Converts the Drupal entity object to a Acquia Content Hub CDF array.

Namespace

Drupal\acquia_contenthub\Normalizer

Code

protected function excludedProperties(ContentEntityInterface $entity) {
  $excluded_fields = [
    // Globally excluded fields (for all entity types).
    'global' => [
      // The following properties are always included in constructor, so we do
      // not need to check them again.
      'created',
      'changed',
      'uri',
      'uid',
      // Getting rid of workflow fields.
      'status',
      // Do not send revisions.
      'revision_uid',
      'revision_user',
      'revision_translation_affected',
      'revision_timestamp',
      // Translation fields.
      'content_translation_uid',
      // Do not include comments.
      'comment',
      'comment_count',
      'comment_count_new',
      // Do not include moderation state.
      'moderation_state',
    ],
    // Excluded fields for nodes.
    'node' => [
      // Getting rid of workflow fields.
      'sticky',
      'promote',
    ],
    'file' => [
      'url',
    ],
  ];
  $entity_type_id = $entity
    ->getEntityTypeId();
  $entity_keys = $entity
    ->getEntityType()
    ->getKeys();

  // Ignore specific properties based on the entity type keys.
  $ignored_keys = [
    'uid',
    'id',
    'revision',
    'uuid',
  ];
  $excluded_keys = array_values(array_intersect_key($entity_keys, array_flip($ignored_keys)));

  // Provide default excluded properties per entity type.
  if (!isset($excluded_fields[$entity_type_id])) {
    $excluded_fields[$entity_type_id] = [];
  }
  $excluded = array_merge($excluded_fields['global'], $excluded_fields[$entity_type_id], $excluded_keys);
  $excluded_to_alter = [];

  // Allow users to define more excluded properties.
  // Allow other modules to intercept and define what default type they want
  // to use for their data type.
  $this->moduleHandler
    ->alter('acquia_contenthub_exclude_fields', $excluded_to_alter, $entity);
  $excluded = array_merge($excluded, $excluded_to_alter);
  return array_filter($excluded);
}