public function DiffController::compareEntityRevisions in Entity Share 8.2
Returns a table which shows the differences between two entity revisions.
Parameters
\Drupal\Core\Routing\RouteMatchInterface $route_match: The route match.
\Drupal\Core\Entity\ContentEntityInterface $left_revision: The left revision.
\Drupal\Core\Entity\ContentEntityInterface $right_revision: The right revision.
string $filter: If $filter == 'raw' raw text is compared (including html tags) If filter == 'raw-plain' markdown function is applied to the text before comparison.
Return value
array Table showing the diff between the two entity revisions.
Overrides PluginRevisionController::compareEntityRevisions
1 call to DiffController::compareEntityRevisions()
- DiffController::compareEntities in modules/
entity_share_client/ src/ Controller/ DiffController.php - Returns a table showing the differences between local and remote entities.
File
- modules/
entity_share_client/ src/ Controller/ DiffController.php, line 146
Class
- DiffController
- Returns responses for Diff support routes.
Namespace
Drupal\entity_share_client\ControllerCode
public function compareEntityRevisions(RouteMatchInterface $route_match, ContentEntityInterface $left_revision, ContentEntityInterface $right_revision, $filter) {
$entity = $left_revision;
// Get language from the entity context.
$langcode = $entity
->language()
->getId();
// Get left and right revision in current language.
$left_revision = $left_revision
->getTranslation($langcode);
$right_revision = $right_revision
->getTranslation($langcode);
$build = [
'#title' => $this
->t('Changes to %title', [
'%title' => $entity
->label(),
]),
'header' => [
'#prefix' => '<header class="diff-header">',
'#suffix' => '</header>',
],
'controls' => [
'#prefix' => '<div class="diff-controls">',
'#suffix' => '</div>',
],
];
// Perform comparison only if both entity revisions loaded successfully.
if ($left_revision != FALSE && $right_revision != FALSE) {
// Build the diff comparison with the plugin.
if ($plugin = $this->diffLayoutManager
->createInstance($filter)) {
$build = array_merge_recursive($build, $plugin
->build($left_revision, $right_revision, $entity));
unset($build['header']);
unset($build['controls']);
// Changes diff table header.
$left_changed = '';
if (method_exists($left_revision, 'getChangedTime')) {
$left_changed = $this->dateFormatter
->format($left_revision
->getChangedTime(), 'short');
}
$build['diff']['#header'][0]['data']['#markup'] = $this
->t('Local entity: @changed', [
'@changed' => $left_changed,
]);
$right_changed = '';
if (method_exists($right_revision, 'getChangedTime')) {
$right_changed = $this->dateFormatter
->format($right_revision
->getChangedTime(), 'short');
}
$build['diff']['#header'][1]['data']['#markup'] = $this
->t('Remote entity: @changed', [
'@changed' => $right_changed,
]);
$build['diff']['#prefix'] = '<div class="diff-responsive-table-wrapper">';
$build['diff']['#suffix'] = '</div>';
$build['diff']['#attributes']['class'][] = 'diff-responsive-table';
}
}
$build['#attached']['library'][] = 'diff/diff.general';
return $build;
}