You are here

protected function ContentImporter::isValidEntityField in Content Synchronization 3.0.x

Same name and namespace in other branches
  1. 8.2 src/Importer/ContentImporter.php \Drupal\content_sync\Importer\ContentImporter::isValidEntityField()

Checks if the entity field needs to be synchronized.

Parameters

ContentEntityInterface $original_entity: The original entity.

ContentEntityInterface $entity: The entity.

string $field_name: The field name.

Return value

bool True if the field needs to be synced.

1 call to ContentImporter::isValidEntityField()
ContentImporter::prepareEntity in src/Importer/ContentImporter.php

File

src/Importer/ContentImporter.php, line 286

Class

ContentImporter

Namespace

Drupal\content_sync\Importer

Code

protected function isValidEntityField(ContentEntityInterface $original_entity, ContentEntityInterface $entity, $field_name) {
  $valid = TRUE;
  $entity_keys = $entity
    ->getEntityType()
    ->getKeys();

  // Check if the target entity has the field.
  if (!$entity
    ->hasField($field_name)) {
    $valid = FALSE;
  }
  elseif (in_array($field_name, $entity_keys, TRUE)) {

    // Unchanged values for entity keys don't need access checking.
    if ($original_entity
      ->get($field_name)
      ->getValue() === $entity
      ->get($field_name)
      ->getValue() || isset($entity_keys['langcode']) && $field_name === $entity_keys['langcode'] && $entity
      ->get($field_name)
      ->isEmpty() || $field_name === $entity
      ->getEntityType()
      ->getKey('id') || $entity
      ->getEntityType()
      ->isRevisionable() && $field_name === $entity
      ->getEntityType()
      ->getKey('revision')) {
      $valid = FALSE;
    }
  }
  return $valid;
}