SilverStripe\Versioned\DataDifferencer
Utility class to render views of the differences between two data objects (or two versions of the same data object).
Construcing a diff object is done as follows:
<code>
$fromRecord = Versioned::get_version('SiteTree', $pageID, $fromVersion);
$toRecord = Versioned::get_version('SiteTree, $pageID, $toVersion);
$diff = new DataDifferencer($fromRecord, $toRecord);
</code>
And then it can be used in a number of ways. You can use the ChangedFields() method in a template:
<pre>
<dl class="diff">
<% with Diff %>
<% loop ChangedFields %>
<dt>$Title</dt>
<dd>$Diff</dd>
<% end_loop %>
<% end_with %>
</dl>
</pre>
Or you can get the diff'ed content as another DataObject, that you can insert into a form.
<code>
$form->loadDataFrom($diff->diffedData());
</code>
If there are fields whose changes you aren't interested in, you can ignore them like so:
<code>
$diff->ignoreFields('AuthorID', 'Status');
</code>
Synopsis
- // members
- protected $fromRecord;
- protected $toRecord;
- protected array $ignoredFields = ;
- // methods
- public void __construct()
- public $this ignoreFields()
- public void diffedData()
- protected string getObjectDisplay()
- public void ChangedFields()
- public void changedFieldNames()
Hierarchy
Extends
- SilverStripe\View\ViewableData
Tasks
Line | Task |
---|---|
190 | Use CMSThumbnail instead to limit max size, blocked by DataDifferencerTest and GC |
Members
protected
- $fromRecord
- $ignoredFields
- $toRecord
Methods
protected
- getObjectDisplay() — Get HTML to display for a dataobject
public
- __construct() — Construct a DataDifferencer to show the changes between $fromRecord and $toRecord.
- ChangedFields() — Get a SS_List of the changed fields.
- changedFieldNames() — Get an array of the names of every fields that has changed.
- diffedData() — Get a DataObject with altered values replaced with HTML diff strings, incorporating <ins> and <del> tags.
- ignoreFields() — Specify some fields to ignore changes from. Repeated calls are cumulative.