function comment_alter_get_rows_diff in Comment Alter 8
Prepare the table rows for theme 'table'.
Parameters
string $a: The source string to compare from.
string $b: The target string to compare to.
boolean $show_header: Display diff context headers. For example, "Line x".
array $line_stats: This structure tracks line numbers across multiple calls to DiffFormatter.
Return value
array Array of rows usable with theme('table').
1 call to comment_alter_get_rows_diff()
- comment_alter_get_changed_fields in ./
comment_alter.module - Returns a table showing the differences committed with a particular comment.
File
- ./
comment_alter.module, line 493 - Allows to alter entities from comment form.
Code
function comment_alter_get_rows_diff($a, $b, $show_header = FALSE, &$line_stats = NULL) {
$a = is_array($a) ? $a : explode("\n", $a);
$b = is_array($b) ? $b : explode("\n", $b);
// Temporary workaround: when comparing with an empty string, Diff Component
// returns a change OP instead of an add OP.
if (count($a) == 1 && $a[0] == "") {
$a = [];
}
if (!isset($line_stats)) {
$line_stats = [
'counter' => [
'x' => 0,
'y' => 0,
],
'offset' => [
'x' => 0,
'y' => 0,
],
];
}
// Header is the line counter.
$container = \Drupal::getContainer();
$diff_formatter = $container
->get('diff.diff.formatter');
$diff_formatter->show_header = $show_header;
$diff = new Diff($a, $b);
return $diff_formatter
->format($diff);
}