You are here

protected function DiffController::prepareHeaderlabels in Entity Share 8.3

Helper: prepare left and right header labels.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $left_entity: The Drupal entity (local).

array $remote_entity_data: Used for remote entity: entity data coming from JSON:API.

Return value

array Array with left and right header labels.

1 call to DiffController::prepareHeaderlabels()
DiffController::compareEntities in modules/entity_share_diff/src/Controller/DiffController.php
Returns a table showing the differences between local and remote entities.

File

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

Class

DiffController
Returns responses for Diff support routes.

Namespace

Drupal\entity_share_diff\Controller

Code

protected function prepareHeaderlabels(ContentEntityInterface $left_entity, array $remote_entity_data) {
  $header = [];

  // Changes diff table header.
  if (method_exists($left_entity, 'getChangedTime')) {
    $left_changed = $this->dateFormatter
      ->format($left_entity
      ->getChangedTime(), 'short');
    $header['left_label'] = $this
      ->t('Local entity: @changed', [
      '@changed' => $left_changed,
    ]);
  }
  else {
    $header['left_label'] = $this
      ->t('Local entity');
  }

  // Changes diff table header.
  $right_changed = $this->entityParser
    ->getRemoteChangedTime($remote_entity_data);
  if ($right_changed) {
    $right_changed = $this->dateFormatter
      ->format($right_changed, 'short');
    $header['right_label'] = $this
      ->t('Remote entity: @changed', [
      '@changed' => $right_changed,
    ]);
  }
  else {
    $header['right_label'] = $this
      ->t('Remote entity');
  }
  return $header;
}