You are here

public function DiffController::compareEntities in Entity Share 8.3

Returns a table showing the differences between local and remote entities.

Parameters

int $left_revision_id: The revision id of the local entity.

\Drupal\entity_share_client\Entity\RemoteInterface $remote: The remote from which the entity is from.

string $channel_id: The channel ID from which the entity is from. Used to handle language.

string $uuid: The UUID of the entity.

Return value

array Table showing the diff between the local and remote entities.

1 string reference to 'DiffController::compareEntities'
entity_share_diff.routing.yml in modules/entity_share_diff/entity_share_diff.routing.yml
modules/entity_share_diff/entity_share_diff.routing.yml

File

modules/entity_share_diff/src/Controller/DiffController.php, line 80

Class

DiffController
Returns responses for Diff support routes.

Namespace

Drupal\entity_share_diff\Controller

Code

public function compareEntities(int $left_revision_id, RemoteInterface $remote, string $channel_id, string $uuid) {

  // Reload the remote to have config overrides applied.
  $remote = $this
    ->entityTypeManager()
    ->getStorage('remote')
    ->load($remote
    ->id());
  $channels_infos = $this->remoteManager
    ->getChannelsInfos($remote);

  // Get the left/local revision.
  $entity_type_id = $channels_infos[$channel_id]['channel_entity_type'];
  $storage = $this
    ->entityTypeManager()
    ->getStorage($entity_type_id);
  $left_revision = $storage
    ->loadRevision($left_revision_id);
  $this->entityParser
    ->validateNeedToProcess($left_revision
    ->uuid(), FALSE);
  $local_values = $this->entityParser
    ->prepareLocalEntity($left_revision);
  $left_yaml = explode("\n", Yaml::encode($local_values));

  // Get the right/remote revision.
  $url = $channels_infos[$channel_id]['url'];
  $prepared_url = EntityShareUtility::prepareUuidsFilteredUrl($url, [
    $uuid,
  ]);
  $response = $this->remoteManager
    ->jsonApiRequest($remote, 'GET', $prepared_url);
  $json = Json::decode((string) $response
    ->getBody());

  // There will be only one result.
  $entity_data = current(EntityShareUtility::prepareData($json['data']));
  $this->entityParser
    ->validateNeedToProcess($entity_data['id'], TRUE);
  $remote_values = $this->entityParser
    ->prepareRemoteEntity($entity_data, $remote);
  $right_yaml = explode("\n", Yaml::encode($remote_values));
  $header = $this
    ->prepareHeaderlabels($left_revision, $entity_data);
  return $this
    ->diffGenerator($left_yaml, $right_yaml, $header);
}