You are here

protected function ContentEntityConflictHandler::autoMergeEntityMetadata in Conflict 8.2

Merges entity metadata.

For entities implementing the EntityChangedInterface, the changed time will be merged. For revisionable entities the revision ID will be merged.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity_local_edited: The locally edited entity.

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

array $form: The form array of the entity form. Might be used to retrieve the path to the entity in the form state values or user input.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Might be used to alter the user input to reflect new metadata from the server entity.

1 call to ContentEntityConflictHandler::autoMergeEntityMetadata()
ContentEntityConflictHandler::entityFormEntityBuilder in src/Entity/ContentEntityConflictHandler.php
Entity builder method.

File

src/Entity/ContentEntityConflictHandler.php, line 525

Class

ContentEntityConflictHandler

Namespace

Drupal\conflict\Entity

Code

protected function autoMergeEntityMetadata(ContentEntityInterface $entity_local_edited, ContentEntityInterface $entity_server, $form, FormStateInterface $form_state) {
  if ($entity_local_edited instanceof EntityChangedInterface && $entity_local_edited
    ->getChangedTime() != $entity_server
    ->getChangedTime()) {
    $entity_local_edited
      ->setChangedTime($entity_server
      ->getChangedTime());

    // We have to update the changed timestamp stored as hidden value in the
    // form to the new value resulted from the merge, otherwise the old one
    // will be mapped on submit.
    $changed_path = $form['#parents'];
    $changed_path[] = 'changed';
    $input =& $form_state
      ->getUserInput();
    NestedArray::setValue($input, $changed_path, $entity_local_edited
      ->getChangedTime());
  }
  if ($this->entityType
    ->isRevisionable()) {
    $entity_local_edited
      ->set($this->entityType
      ->getKey('revision'), $entity_server
      ->getRevisionId());
    $entity_local_edited
      ->updateLoadedRevisionId();
  }
}