\Drupal\strata\Diff FieldDiff

What changed in one field, setting or column, between two points in time.

A field is either scalar or it is not, and the two want different renderings: a title going from one string to another is a single line, and a body going from one paragraph to another is a run of hunks. Both are carried here so the renderer picks rather than guesses, and isTextual() is the question it asks.

The rendered values are kept alongside the hunks because a field that was added or removed has only one side, and asking a line-level diff to represent "this did not exist" produces a hunk of every line rather than the one fact that matters.

Summary

Methods
Properties
Constants
__construct
isTextual
changedLines
describe
jsonSerialize
name
status
before
after
hunks
CHANGED
ADDED
REMOVED
No protected methods found
No protected properties found
No protected constants found
clip
No private properties found
No private constants found

Constant

CHANGED

CHANGED = 'changed'

The field exists in both and differs.

ADDED

ADDED = 'added'

The field only exists in the later value.

REMOVED

REMOVED = 'removed'

The field only exists in the earlier value.

Properties

$name

$name : string

Type

string

$status

$status : string

Type

string

$before

$before : string

Type

string

$after

$after : string

Type

string

$hunks

$hunks : array

Type

array<string|int, mixed>

Methods

__construct()

__construct(string  $name, string  $status, string  $before = '', string  $after = '', list<\Drupal\strata\Diff\DiffHunk>  $hunks = []) : mixed

Constructs a field diff.

Parameters

string $name

The field, setting or column name.

string $status

One of CHANGED, ADDED or REMOVED.

string $before

The earlier value, rendered.

string $after

The later value, rendered.

list<\Drupal\strata\Diff\DiffHunk> $hunks

Line-level hunks, empty for a value that is not worth diffing by line.

Returns

mixed —

isTextual()

isTextual() : bool

Whether this field is worth rendering as a line-by-line diff.

Returns

bool —

TRUE when there are hunks to draw.

changedLines()

changedLines() : int

How many lines differ.

Returns

int —

Lines across every hunk that is not a copy.

describe()

describe(int  $length = 60) : string

A one-line description of the change.

Parameters

int $length

Characters of a value to show before truncating.

Returns

string —

Something a table cell can hold.

jsonSerialize()

jsonSerialize() : array

{@inheritdoc}

Returns

array —

clip()

clip(string  $value, int  $length) : string

Shortens a value for a table cell.

Parameters

string $value

The value.

int $length

Characters to keep.

Returns

string —

The value, with newlines flattened and an ellipsis when it was cut.