Diff
Compares entity revisions field by field and displays visual differences between them.
diff
インストール
composer require 'drupal/diff:8.x-1.9'
composer require 'drupal/diff:8.x-1.6'
概要
Diff モジュールは、Drupal コンテンツエンティティ向けの高度なリビジョン比較システムを提供します。標準のリビジョンタブを拡張インターフェースに置き換え、コンテンツエンティティの任意の2つのリビジョンを選択して比較できます。
リビジョン比較には複数の表示レイアウトが用意されています:Split Fields(左右並列表示)、Unified Fields(行単位表示)、Visual Inline(エンティティの表示モードを使用したレンダリングHTML比較)。各レイアウトは、リビジョン間でコンテンツがどのように変更されたかを異なる視点で確認できます。
Diff は柔軟なプラグインシステムを使用して、さまざまなフィールドタイプを処理します。Field diff builder プラグインはフィールド値を比較可能な文字列に変換し、レイアウトプラグインは比較の表示方法を決定します。このアーキテクチャにより、さまざまなコンテンツタイプやユースケースに対応した拡張とカスタマイズが可能です。
このモジュールは Content Moderation と統合してリビジョン説明にワークフロー状態の変更を表示し、カスタムリビジョン比較インターフェースを構築するための Views フィールドプラグインも提供します。
Features
- ラジオボタンを使用した左右リビジョン選択が可能な拡張リビジョン概要ページ
- 複数の比較レイアウトオプション:Split Fields(左右並列)、Unified Fields(行単位)、Visual Inline(レンダリングHTML差分)
- フィールドタイプごとに設定可能な field diff builder プラグインによるフィールド単位の比較
- テキストフィールド、エンティティ参照、画像、ファイル、リンク、リストフィールド、コメントフィールドの比較に対応
- 前後の変更へのナビゲーションリンク
- 生コンテンツまたは Markdown 処理済みコンテンツを表示するフィルターオプション
- 設定可能な表示モードでレンダリングされたエンティティ比較のための HtmlDiffAdvanced ライブラリを使用した Visual Inline レイアウト
- リビジョン説明にワークフロー状態を表示する Content Moderation 統合
- カスタムリビジョン比較ビュー用の diff__from および diff__to フィールドプラグインによる Views 統合
- カスタム field diff builder およびレイアウトプラグインを追加可能な拡張性のあるプラグインアーキテクチャ
- リビジョン選択用ラジオボタンの動作設定(Simple exclusion または Linear restrictions)
- フィールドタイトルの表示や Markdown コールバックオプションを含むフィールドごとの差分表示設定
- 差分サポート付きリビジョン可能エンティティタイプの自動ルート生成
Use Cases
Editorial Workflow Review
Content editors can use Diff to review changes made by other team members before publishing. By comparing the current draft with the published version, editors can see exactly what text was added, removed, or modified, making the review process more efficient and accurate.
Content Audit and History Tracking
Administrators can track the evolution of important content over time. By comparing any two historical revisions, they can understand how content has changed, who made changes (via revision log messages), and verify that changes align with content strategy.
Translation Comparison
For multilingual sites, Diff helps translators understand what changed in the source content between translation updates. By comparing revisions of the source language, translators can focus on updating only the portions that changed.
Visual Content Preview
Using the Visual Inline layout, content creators can see how their changes affect the rendered appearance of content. This is particularly useful for complex content types with multiple fields and formatting options.
Custom Revision Views
Site builders can create custom Views displaying revision lists with comparison capabilities. Using the diff__from and diff__to field plugins, users can select any two revisions from a list and compare them directly.
Tips
- Enable only the layout plugins you need to simplify the user interface for content editors
- Use the 'Linear restrictions' radio behavior to guide users toward comparing adjacent revisions chronologically
- Configure the Visual Inline layout to use the 'Diff' view mode for a cleaner comparison focused on content changes
- For image fields, enable thumbnail display in the field diff plugin settings to visualize image changes
- Use markdown callbacks on text fields to strip HTML for cleaner text-only comparisons
- Set appropriate context lines (leading/trailing) based on your content length - fewer lines for short content, more for longer articles
Technical Details
Admin Pages 2
/admin/config/content/diff/general
Configure global settings for the revision comparison functionality including layout plugins, radio button behavior, and context lines for field-based layouts.
/admin/config/content/diff/fields
Configure diff builder plugins for each field type in the system. Select which plugin handles the comparison for each field and configure field-specific settings.
Hooks 2
hook_field_diff_builder_info_alter
Alters field diff builder plugin definitions. Allows modules to modify plugin labels, weights, or other properties.
hook_diff_layout_builder_info_alter
Alters diff layout builder plugin definitions. Allows modules to modify layout plugin labels, descriptions, or other properties.
Troubleshooting 4
The Visual Inline layout requires the php-htmldiff-advanced library. Install it using Composer: composer require caxy/php-htmldiff. The layout will automatically become available once the library is installed.
Check the Fields Settings page at /admin/config/content/diff/fields. Ensure the field has a diff plugin selected (not "Don't compare"). Also verify the field is revisionable and has view display configured.
Ensure the revisions actually contain different values for the compared fields. Check that the field diff plugin is correctly configured. For entity reference fields, verify the comparison method (ID vs Label) matches your expectations.
Adjust the Radio behavior setting at /admin/config/content/diff/general. 'Simple exclusion' prevents selecting the same revision; 'Linear restrictions' enforces chronological selection order.