class DiffFormatter in Entity Share 8.3
Diff formatter which renders a table, with structured padding in HTML.
Hierarchy
- class \Drupal\Component\Diff\DiffFormatter
- class \Drupal\Core\Diff\DiffFormatter
- class \Drupal\entity_share_diff\Diff\DiffFormatter
- class \Drupal\Core\Diff\DiffFormatter
Expanded class hierarchy of DiffFormatter
1 string reference to 'DiffFormatter'
- entity_share_diff.services.yml in modules/
entity_share_diff/ entity_share_diff.services.yml - modules/entity_share_diff/entity_share_diff.services.yml
1 service uses DiffFormatter
- entity_share_diff.formatter in modules/
entity_share_diff/ entity_share_diff.services.yml - Drupal\entity_share_diff\Diff\DiffFormatter
File
- modules/
entity_share_diff/ src/ Diff/ DiffFormatter.php, line 13
Namespace
Drupal\entity_share_diff\DiffView source
class DiffFormatter extends CoreDiffFormatter {
/**
* Is the Diff supposed to be output in an HTML page?
*
* @var bool
*/
public $htmlOutput = FALSE;
/**
* Creates a DiffFormatter to render diffs in a table.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
*/
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'];
}
}
/**
* {@inheritdoc}
*/
protected function addedLine($line) {
$output = parent::addedLine($line);
return $this
->improvePadding($output);
}
/**
* {@inheritdoc}
*/
protected function deletedLine($line) {
$output = parent::deletedLine($line);
return $this
->improvePadding($output);
}
/**
* {@inheritdoc}
*/
protected function contextLine($line) {
$output = parent::contextLine($line);
return $this
->improvePadding($output);
}
/**
* Helper function: replaces initial plain spaces with HTML spaces in markup.
*
* @param array $output
* An array representing a table row.
*
* @return array
* An array representing a table row.
*/
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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DiffFormatter:: |
public | property | Is the Diff supposed to be output in an HTML page? | |
DiffFormatter:: |
public | property | Number of leading context "lines" to preserve. | |
DiffFormatter:: |
protected | property | The line stats. | |
DiffFormatter:: |
protected | property | The diff represented as an array of rows. | |
DiffFormatter:: |
public | property | Should a block header be shown? | |
DiffFormatter:: |
public | property | Number of trailing context "lines" to preserve. | |
DiffFormatter:: |
protected | function |
Creates an added line. Overrides DiffFormatter:: |
|
DiffFormatter:: |
protected | function |
Creates a context line. Overrides DiffFormatter:: |
|
DiffFormatter:: |
protected | function |
Creates a deleted line. Overrides DiffFormatter:: |
|
DiffFormatter:: |
protected | function | Creates an empty line. | |
DiffFormatter:: |
public | function | Format a diff. | |
DiffFormatter:: |
protected | function | Helper function: replaces initial plain spaces with HTML spaces in markup. | |
DiffFormatter:: |
protected | function |
Overrides DiffFormatter:: |
|
DiffFormatter:: |
protected | function | ||
DiffFormatter:: |
protected | function |
Overrides DiffFormatter:: |
|
DiffFormatter:: |
protected | function |
Overrides DiffFormatter:: |
|
DiffFormatter:: |
protected | function |
Overrides DiffFormatter:: |
|
DiffFormatter:: |
protected | function |
Overrides DiffFormatter:: |
|
DiffFormatter:: |
protected | function | ||
DiffFormatter:: |
protected | function |
Overrides DiffFormatter:: |
|
DiffFormatter:: |
protected | function |
Overrides DiffFormatter:: |
|
DiffFormatter:: |
protected | function |
Overrides DiffFormatter:: |
|
DiffFormatter:: |
protected | function |
Overrides DiffFormatter:: |
|
DiffFormatter:: |
public | function |
Creates a DiffFormatter to render diffs in a table. Overrides DiffFormatter:: |