You are here

public function ContentEntityConflictHandler::getConflicts in Conflict 8.2

Returns the entity conflicts.

Parameters

\Drupal\Core\Entity\EntityInterface $entity_local_original: The locally edited entity.

\Drupal\Core\Entity\EntityInterface $entity_local_edited: The original not edited entity used to build the form.

\Drupal\Core\Entity\EntityInterface $entity_server: The unchanged entity loaded from the storage.

Return value

array An array of conflicts, keyed by the field name having as value the conflict type.

Overrides EntityConflictHandlerInterface::getConflicts

1 call to ContentEntityConflictHandler::getConflicts()
ContentEntityConflictHandler::autoMergeNotTouchedFields in src/Entity/ContentEntityConflictHandler.php
Merges non-touched fields i.e. prevents reverts.

File

src/Entity/ContentEntityConflictHandler.php, line 604

Class

ContentEntityConflictHandler

Namespace

Drupal\conflict\Entity

Code

public function getConflicts(EntityInterface $entity_local_original, EntityInterface $entity_local_edited, EntityInterface $entity_server) {
  $conflicts = [];
  $entity_type_id = $this->entityType
    ->id();
  $entity_bundle = $entity_local_edited
    ->bundle();
  $langcode = $entity_local_edited
    ->language()
    ->getId();
  $entity_server = $entity_server
    ->getTranslation($langcode);
  $entity_local_original = $entity_local_original
    ->getTranslation($langcode);

  // The revision created field is updated constantly and it will always cause
  // conflicts, therefore we skip it here, as it gets updated correctly on
  // submit during entity building from user input.
  // @see \Drupal\Core\Entity\ContentEntityForm::buildEntity().
  $skip_fields = array_flip($this->entityType
    ->getRevisionMetadataKeys());
  foreach ($entity_local_edited
    ->getFields() as $field_name => $field_items_list_local_edited) {
    if (isset($skip_fields[$field_name])) {
      continue;
    }
    $field_definition = $field_items_list_local_edited
      ->getFieldDefinition();

    // There could be no conflicts in read only fields.
    if ($field_definition
      ->isReadOnly()) {
      continue;
    }
    $field_type = $field_definition
      ->getType();
    $field_items_list_server = $entity_server
      ->get($field_name);
    $field_items_list_local_original = $entity_local_original
      ->get($field_name);
    $conflict_type = $this->fieldComparatorManager
      ->getConflictType($field_items_list_local_edited, $field_items_list_server, $field_items_list_local_original, $langcode, $entity_type_id, $entity_bundle, $field_type, $field_name);
    if ($conflict_type) {
      $conflicts[$field_name] = $conflict_type;
    }
  }
  return $conflicts;
}