You are here

public function EntityProcessorBase::getDefaultLanguageData in Content Synchronizer 3.x

Same name and namespace in other branches
  1. 8.2 src/Processors/Entity/EntityProcessorBase.php \Drupal\content_synchronizer\Processors\Entity\EntityProcessorBase::getDefaultLanguageData()
  2. 8 src/Processors/Entity/EntityProcessorBase.php \Drupal\content_synchronizer\Processors\Entity\EntityProcessorBase::getDefaultLanguageData()

Return the data of the default language of the passed data.

2 calls to EntityProcessorBase::getDefaultLanguageData()
EntityProcessorBase::getEntityToImport in src/Processors/Entity/EntityProcessorBase.php
Return the entity to import.
TaxonomyTermProcessor::getEntityToImport in src/Plugin/content_synchronizer/entity_processor/TaxonomyTermProcessor.php
Return the entity to import.

File

src/Processors/Entity/EntityProcessorBase.php, line 137

Class

EntityProcessorBase
The entity processor base.

Namespace

Drupal\content_synchronizer\Processors\Entity

Code

public function getDefaultLanguageData(array $data, $filterOnEntityDefinition = TRUE) {
  if (count($data[self::KEY_TRANSLATIONS]) > 1) {
    foreach ($data[self::KEY_TRANSLATIONS] as $translationData) {
      if (array_key_exists('default_langcode', $translationData) && $translationData['default_langcode'][0]['value'] == 1) {
        return $translationData;
      }
    }
  }

  // Get default data :
  $defaultData = reset($data[self::KEY_TRANSLATIONS]);
  if ($filterOnEntityDefinition) {

    // Filter on reference data field.
    $entityTypeId = $this
      ->getGlobalReferenceManager()
      ->getEntityTypeFromGid($data[ExportEntityWriter::FIELD_GID]);

    // Get the bundle of the entity.
    $entityDefinition = \Drupal::entityTypeManager()
      ->getDefinition($entityTypeId);
    $bundleKey = $entityDefinition
      ->getKey('bundle');
    $bundle = $defaultData[$bundleKey];

    // Get field definitions.
    $fieldDefinitions = \Drupal::service('entity_field.manager')
      ->getFieldDefinitions($entityTypeId, $bundle);
    return array_intersect_key($defaultData, $fieldDefinitions);
  }
  else {
    return $defaultData;
  }
}