EvaluateDisplayConditions

class \TYPO3\CMS\Backend\Form\FormDataProvider\EvaluateDisplayConditions

Implements
FormDataProviderInterface

Class implements the TCA 'displayCond' option.

The display condition is a colon separated string which describes the condition to decide whether a form field should be displayed.

Table of Contents

Interfaces

FormDataProviderInterface
Interface must be implemented by form data provider classes.

Methods

addData()  : array
Remove fields from processedTca columns that should not be displayed.
evaluateConditionRecursive()  : bool
Evaluate a condition recursive by evaluating the single condition type
evaluateConditions()  : array
Loop through TCA, find prepared conditions and evaluate them. Delete either the field itself if the condition did not match, or the 'displayCond' in TCA.
findFieldValue()  : mixed
Find field value the condition refers to for "FIELD:" conditions. For "normal" TCA fields this is the value of a "neighbor" field, but in flex form context it can be prepended with a sheet name. The method sorts out the details and returns the current field value.
getBackendUser()  : BackendUserAuthentication
matchFieldCondition()  : bool
Evaluates conditions concerning a field of the current record.
matchRecordCondition()  : bool
Evaluates conditions concerning the status of the current record.
matchUserCondition()  : bool
Evaluates via the referenced user-defined method
matchVersionCondition()  : bool
Evaluates whether the current record is versioned.
parseConditionRecursive()  : array
Parse a condition into an array representation and validate syntax. Handles nested conditions combined with AND and OR.
parseDisplayConditions()  : array
Find all 'displayCond' in TCA and flex forms and substitute them with an array representation that contains all relevant data to evaluate the condition later. For "FIELD" conditions the helper methods findFieldValue() is used to find the value of the referenced field to put that value into the returned array, too. This is important since the referenced field is "relative" to the position of the field that has the display condition.
parseSingleConditionString()  : array
Parse a single condition string into pieces, validate them and return an array representation.

Methods

addData()

Remove fields from processedTca columns that should not be displayed.

public addData(array $result) : array

Strategy of the parser is to first find all displayCond in given tca and within all type=flex fields to parse them into an array. This condition array contains all information to evaluate that condition in a second step that - depending on evaluation result - then throws away or keeps the field.

Parameters

$result : array

Return values

array —

Result filled with more data

evaluateConditionRecursive()

Evaluate a condition recursive by evaluating the single condition type

protected evaluateConditionRecursive(array $conditionArray) : bool

Parameters

$conditionArray : array

The condition to evaluate, possibly with subConditions for AND and OR types

Return values

bool —

true if the condition matched

evaluateConditions()

Loop through TCA, find prepared conditions and evaluate them. Delete either the field itself if the condition did not match, or the 'displayCond' in TCA.

protected evaluateConditions(array $result) : array

Parameters

$result : array

Return values

array

findFieldValue()

Find field value the condition refers to for "FIELD:" conditions. For "normal" TCA fields this is the value of a "neighbor" field, but in flex form context it can be prepended with a sheet name. The method sorts out the details and returns the current field value.

protected findFieldValue(string $givenFieldName, array $databaseRow[, array $flexContext = [] ]) : mixed

Parameters

$givenFieldName : string

The full name used in displayCond. Can have sheet names included in flex context

$databaseRow : array

Incoming database row values

$flexContext : array = []

Detailed flex context if display condition is within a flex field, needed to determine field value for "FIELD" conditions

Tags

throws
RuntimeException

Return values

mixed —

The current field value from database row or a deeper flex form structure field.

matchFieldCondition()

Evaluates conditions concerning a field of the current record.

protected matchFieldCondition(array $condition) : bool

Example: "FIELD:sys_language_uid:>:0" => TRUE, if the field 'sys_language_uid' is greater than 0

Parameters

$condition : array

Condition array

Return values

bool

matchRecordCondition()

Evaluates conditions concerning the status of the current record.

protected matchRecordCondition(array $condition) : bool

Example: "REC:NEW:FALSE" => TRUE, if the record is already persisted (has a uid > 0)

Parameters

$condition : array

Condition array

Return values

bool

matchUserCondition()

Evaluates via the referenced user-defined method

protected matchUserCondition(array $condition) : bool

Parameters

$condition : array

Condition array

Return values

bool

matchVersionCondition()

Evaluates whether the current record is versioned.

protected matchVersionCondition(array $condition) : bool

Parameters

$condition : array

Condition array

Return values

bool

parseConditionRecursive()

Parse a condition into an array representation and validate syntax. Handles nested conditions combined with AND and OR.

protected parseConditionRecursive(mixed $condition, array $databaseRow[, array $flexContext = [] ]) : array

Calls itself recursive for nesting and logically combined conditions.

Parameters

$condition : mixed

Either an array with multiple conditions combined with AND or OR, or a single condition string

$databaseRow : array

Incoming full database row

$flexContext : array = []

Detailed flex context if display condition is within a flex field, needed to determine field value for "FIELD" conditions

Tags

throws
RuntimeException

Return values

array —

Array representation of that condition, see unit tests for details on syntax

parseDisplayConditions()

Find all 'displayCond' in TCA and flex forms and substitute them with an array representation that contains all relevant data to evaluate the condition later. For "FIELD" conditions the helper methods findFieldValue() is used to find the value of the referenced field to put that value into the returned array, too. This is important since the referenced field is "relative" to the position of the field that has the display condition.

protected parseDisplayConditions(array $result) : array

For instance, "FIELD:aField:=:foo" within a flex form field references a field value from the same sheet, and there are many more complex scenarios to resolve.

Parameters

$result : array

Incoming result array

Tags

throws
RuntimeException

Return values

array —

Modified result array with all displayCond parsed into arrays

parseSingleConditionString()

Parse a single condition string into pieces, validate them and return an array representation.

protected parseSingleConditionString(string $conditionString, array $databaseRow[, array $flexContext = [] ]) : array

Parameters

$conditionString : string

Given condition string like "VERSION:IS:true"

$databaseRow : array

Incoming full database row

$flexContext : array = []

Detailed flex context if display condition is within a flex field, needed to determine field value for "FIELD" conditions

Tags

throws
RuntimeException

Return values

array —

Validated name array, example: [ type="VERSION", isVersion="true" ]

On this page