class VisualInlineDiffLayout in Diff 8
Provides Visual Inline diff layout.
Plugin annotation
@DiffLayoutBuilder(
id = "visual_inline",
label = @Translation("Visual Inline"),
description = @Translation("Visual layout, displays revision comparison using the entity type view mode."),
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\diff\DiffLayoutBase implements ContainerFactoryPluginInterface, DiffLayoutInterface uses StringTranslationTrait
- class \Drupal\diff\Plugin\diff\Layout\VisualInlineDiffLayout
- class \Drupal\diff\DiffLayoutBase implements ContainerFactoryPluginInterface, DiffLayoutInterface uses StringTranslationTrait
Expanded class hierarchy of VisualInlineDiffLayout
File
- src/
Plugin/ diff/ Layout/ VisualInlineDiffLayout.php, line 29
Namespace
Drupal\diff\Plugin\diff\LayoutView source
class VisualInlineDiffLayout extends DiffLayoutBase {
/**
* The renderer.
*
* @var \Drupal\Core\Render\RendererInterface
*/
protected $renderer;
/**
* The diff entity comparison service.
*
* @var \Drupal\diff\DiffEntityComparison
*/
protected $entityComparison;
/**
* The html diff service.
*
* @var \HtmlDiffAdvancedInterface
*/
protected $htmlDiff;
/**
* The request stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected $requestStack;
/**
* The entity display repository.
*
* @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface
*/
protected $entityDisplayRepository;
/**
* Constructs a VisualInlineDiffLayout object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config
* The configuration factory object.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\diff\DiffEntityParser $entity_parser
* The entity parser.
* @param \Drupal\Core\DateTime\DateFormatter $date
* The date service.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The renderer.
* @param \Drupal\diff\DiffEntityComparison $entity_comparison
* The diff entity comparison service.
* @param \HtmlDiffAdvancedInterface $html_diff
* The html diff service.
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack.
* @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_repository
* The entity display repository.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config, EntityTypeManagerInterface $entity_type_manager, DiffEntityParser $entity_parser, DateFormatter $date, RendererInterface $renderer, DiffEntityComparison $entity_comparison, HtmlDiffAdvancedInterface $html_diff, RequestStack $request_stack, EntityDisplayRepositoryInterface $entity_display_repository) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $config, $entity_type_manager, $entity_parser, $date);
$this->renderer = $renderer;
$this->entityComparison = $entity_comparison;
$storage = PhpStorageFactory::get('html_purifier_serializer');
if (!$storage
->exists('cache.php')) {
$storage
->save('cache.php', 'dummy');
}
$html_diff
->getConfig()
->setPurifierCacheLocation(dirname($storage
->getFullPath('cache.php')));
$this->htmlDiff = $html_diff;
$this->requestStack = $request_stack;
$this->entityDisplayRepository = $entity_display_repository;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('config.factory'), $container
->get('entity_type.manager'), $container
->get('diff.entity_parser'), $container
->get('date.formatter'), $container
->get('renderer'), $container
->get('diff.entity_comparison'), $container
->get('diff.html_diff'), $container
->get('request_stack'), $container
->get('entity_display.repository'));
}
/**
* {@inheritdoc}
*/
public function build(ContentEntityInterface $left_revision, ContentEntityInterface $right_revision, ContentEntityInterface $entity) {
// Build the revisions data.
$build = $this
->buildRevisionsData($left_revision, $right_revision);
$this->entityTypeManager
->getStorage($entity
->getEntityTypeId())
->resetCache([
$entity
->id(),
]);
// Build the view modes filter.
$options = [];
// Get all view modes for entity type.
$view_modes = $this->entityDisplayRepository
->getViewModeOptionsByBundle($entity
->getEntityTypeId(), $entity
->bundle());
foreach ($view_modes as $view_mode => $view_mode_info) {
// Skip view modes that are not used in the front end.
if (in_array($view_mode, [
'rss',
'search_index',
])) {
continue;
}
$options[$view_mode] = [
'title' => $view_mode_info,
'url' => PluginRevisionController::diffRoute($entity, $left_revision
->getRevisionId(), $right_revision
->getRevisionId(), 'visual_inline', [
'view_mode' => $view_mode,
]),
];
}
$active_option = array_keys($options);
$active_view_mode = $this->requestStack
->getCurrentRequest()->query
->get('view_mode') ?: reset($active_option);
$filter = $options[$active_view_mode];
unset($options[$active_view_mode]);
array_unshift($options, $filter);
$build['controls']['view_mode'] = [
'#type' => 'item',
'#title' => $this
->t('View mode'),
'#wrapper_attributes' => [
'class' => 'diff-controls__item',
],
'filter' => [
'#type' => 'operations',
'#links' => $options,
],
];
$view_builder = $this->entityTypeManager
->getViewBuilder($entity
->getEntityTypeId());
// Trigger exclusion of interactive items like on preview.
$left_revision->in_preview = TRUE;
$right_revision->in_preview = TRUE;
$left_view = $view_builder
->view($left_revision, $active_view_mode);
$right_view = $view_builder
->view($right_revision, $active_view_mode);
// Avoid render cache from being built.
unset($left_view['#cache']);
unset($right_view['#cache']);
$html_1 = $this->renderer
->render($left_view);
$html_2 = $this->renderer
->render($right_view);
$this->htmlDiff
->setOldHtml($html_1);
$this->htmlDiff
->setNewHtml($html_2);
$this->htmlDiff
->build();
$build['diff'] = [
'#markup' => $this->htmlDiff
->getDifference(),
'#weight' => 10,
];
$build['#attached']['library'][] = 'diff/diff.visual_inline';
return $build;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DiffLayoutBase:: |
protected | property | Contains the configuration object factory. | |
DiffLayoutBase:: |
protected | property | The date service. | |
DiffLayoutBase:: |
protected | property | The entity parser. | |
DiffLayoutBase:: |
protected | property | The entity type manager. | |
DiffLayoutBase:: |
protected | function | Applies a markdown function to a string. | |
DiffLayoutBase:: |
public | function |
Form constructor. Overrides PluginFormInterface:: |
|
DiffLayoutBase:: |
protected | function | Build the filter navigation for the diff comparison. | |
DiffLayoutBase:: |
protected | function | Build the revision link for a revision. | |
DiffLayoutBase:: |
protected | function | Build the revision link for a revision. | |
DiffLayoutBase:: |
public | function | Build the revision link for the compared revisions. | |
DiffLayoutBase:: |
public | function |
Gets default configuration for this plugin. Overrides ConfigurableInterface:: |
|
DiffLayoutBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
DiffLayoutBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
DiffLayoutBase:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
|
DiffLayoutBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
VisualInlineDiffLayout:: |
protected | property | The diff entity comparison service. | |
VisualInlineDiffLayout:: |
protected | property | The entity display repository. | |
VisualInlineDiffLayout:: |
protected | property | The html diff service. | |
VisualInlineDiffLayout:: |
protected | property | The renderer. | |
VisualInlineDiffLayout:: |
protected | property | The request stack. | |
VisualInlineDiffLayout:: |
public | function |
Builds a diff comparison between two revisions. Overrides DiffLayoutInterface:: |
|
VisualInlineDiffLayout:: |
public static | function |
Creates an instance of the plugin. Overrides DiffLayoutBase:: |
|
VisualInlineDiffLayout:: |
public | function |
Constructs a VisualInlineDiffLayout object. Overrides DiffLayoutBase:: |