DiffFormatter.php in Entity Share 8.3
File
modules/entity_share_diff/src/Diff/DiffFormatter.php
View source
<?php
declare (strict_types=1);
namespace Drupal\entity_share_diff\Diff;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Diff\DiffFormatter as CoreDiffFormatter;
class DiffFormatter extends CoreDiffFormatter {
public $htmlOutput = FALSE;
public function __construct(ConfigFactoryInterface $config_factory) {
parent::__construct($config_factory);
$config = $config_factory
->get('entity_share_diff.settings');
$context_settings = $config
->get('context');
if ($context_settings) {
$this->leading_context_lines = $context_settings['lines_leading'];
$this->leading_context_lines = $context_settings['lines_trailing'];
}
}
protected function addedLine($line) {
$output = parent::addedLine($line);
return $this
->improvePadding($output);
}
protected function deletedLine($line) {
$output = parent::deletedLine($line);
return $this
->improvePadding($output);
}
protected function contextLine($line) {
$output = parent::contextLine($line);
return $this
->improvePadding($output);
}
protected function improvePadding(array $output) {
if (!$this->htmlOutput) {
return $output;
}
$markup = $output[1]['data']['#markup'];
$trimmed_markup = ltrim($markup);
$diff_length = strlen($markup) - strlen($trimmed_markup);
if ($diff_length > 0) {
$output[1]['data']['#markup'] = str_repeat(' ', $diff_length) . $trimmed_markup;
}
return $output;
}
}
Classes
Name |
Description |
DiffFormatter |
Diff formatter which renders a table, with structured padding in HTML. |