You are here

protected function ContentEntityNormalizer::cleanupData in Content Synchronization 8.2

Same name and namespace in other branches
  1. 3.0.x src/Normalizer/ContentEntityNormalizer.php \Drupal\content_sync\Normalizer\ContentEntityNormalizer::cleanupData()

Parameters

$data:

$entity_type_id:

1 call to ContentEntityNormalizer::cleanupData()
ContentEntityNormalizer::denormalize in src/Normalizer/ContentEntityNormalizer.php
Denormalizes data back into an object of the given class.

File

src/Normalizer/ContentEntityNormalizer.php, line 294

Class

ContentEntityNormalizer
Adds the file URI to embedded file entities.

Namespace

Drupal\content_sync\Normalizer

Code

protected function cleanupData(&$data, $entity_type_id, $bundle = FALSE) {
  if ($bundle) {
    $field_definitions = $this->entityFieldManager
      ->getFieldDefinitions($entity_type_id, $bundle);
  }
  else {
    $bundles = array_keys($this->entityTypeBundleInfo
      ->getBundleInfo($entity_type_id));
    $field_definitions = [];
    foreach ($bundles as $bundle) {
      $field_definitions_bundle = $this->entityFieldManager
        ->getFieldDefinitions($entity_type_id, $bundle);
      if (is_array($field_definitions_bundle)) {
        $field_definitions += $field_definitions_bundle;
      }
    }
  }
  $field_names = array_keys($field_definitions);
  foreach ($data as $field_name => $field_data) {
    if (!in_array($field_name, $field_names)) {
      unset($data[$field_name]);
    }
  }
}