DataMapProcessor

class \TYPO3\CMS\Core\DataHandling\Localization\DataMapProcessor

This processor analyzes the provided data-map before actually being process in the calling DataHandler instance. Field names that are configured to have "allowLanguageSynchronization" enabled are either synchronized from there relative parent records (could be a default language record, or a l10n_source record) or to their dependent records (in case a default language record or nested records pointing upwards with l10n_source).

Except inline relational record editing, all modifications are applied to the data-map directly, which ensures proper history entries as a side-effect. For inline relational record editing, this processor either triggers the copy or localize actions by instantiation a new local DataHandler instance.

Namings in this class:

  • forTableName, forId always refers to dependencies data is provided for
  • fromTableName, fromId always refers to ancestors data is retrieved from

Table of Contents

Properties

$allDataMap  : array
$allItems  : DataMapItem[]
$backendUser  : BackendUserAuthentication
$modifiedDataMap  : array<string, array>
$nextItems  : DataMapItem[]
$referenceIndexUpdater  : ReferenceIndexUpdater
$sanitizationMap  : array<string, array<int, array>>

Methods

instance()  : DataMapProcessor
Class generator
process()  : array
Processes the submitted data-map and returns the sanitized and enriched version depending on accordant localization states and dependencies.
addNextItem()  : void
applyLocalizationReferences()  : array
Applies localization references to given raw data-map item.
buildElementAncestorIdMap()  : array
Builds a map from ancestor ids to accordant localization dependents.
collectItems()  : void
Create data map items of all affected rows
createRelationHandler()  : RelationHandler
enrich()  : mixed
Handle synchronization of an item list
fetchDependencies()  : array<int|string, array<string, array<int, DataMapItem>>>
Fetches translation dependencies for a given parent/source record ids.
fetchDependentElements()  : array
Fetch all elements that depend on given record id's in either their parent or source field for translatable tables or their origin field for non-translatable tables.
fetchDependentIdMap()  : array
Fetches dependent records that depend on given record id's in in either their parent or source field for translatable tables or their origin field for non-translatable tables and creates an id mapping.
fetchTranslationValues()  : array
Fetches translation related field values for the items submitted in the data-map.
filterItemsByType()  : DataMapItem[]
Return array of data map items that are of given type
filterNewItemIds()  : array
Return only ids that don't have an item equivalent in $this->allItems.
filterNumericIds()  : int[]
Return only ids that are integer - so no "NEW..." values
findItem()  : DataMapItem|null
See if an items is in item list and return it
finishTranslationItem()  : mixed
Finishes a translation item by updating states to be persisted.
getFieldNamesForItemScope()  : string[]
Field names we have to deal with
getFieldNamesToBeHandled()  : string[]
Gets a list of field names which have to be handled. Basically this includes fields using allowLanguageSynchronization or l10n_mode=exclude.
getLanguageService()  : LanguageService|null
getLocalizationModeExcludeFieldNames()  : string[]
Field names of TCA table with columns having l10n_mode=exclude
getPrefixLanguageTitleFieldNames()  : array
Field names of TCA table with columns having l10n_mode=prefixLangTitle
getSchema()  : TcaSchema|null
isApplicable()  : bool
Determines whether the table can be localized and either has fields with allowLanguageSynchronization enabled or l10n_mode set to exclude.
isReferenceField()  : bool
True if we're dealing with a reference field (either "inline" or "file")
isRelationField()  : bool
True if we're dealing with a field that has foreign db relations
isSetInDataMap()  : bool
Determines whether a combination of table name, id and field name is set in data-map. This method considers null values as well, that would not be considered by a plain isset() invocation.
mapRelationItemId()  : int[]
Flatten array
modifyDataMap()  : void
Applies modifications to the data-map, calling this method is essential to determine new data-map items to be process for synchronizing chained record localizations.
populateTranslationItem()  : mixed
Populates values downwards, either from a parent language item or a source language item to an accordant dependent translation item.
prefixLanguageTitle()  : array
Prefixes language title if applicable for the accordant field name in raw data-map item.
purgeDataMap()  : array
Purges superfluous empty data-map sections.
resolveAncestorId()  : int|null
resolveSuggestedInlineRelations()  : int[]|string[]
Determines suggest inline relations of either translation parent or source record from data-map or storage in case records have been persisted already.
sanitize()  : mixed
Sanitizes the submitted data-map items and removes fields which are not defined as custom and thus rely on either parent or source values.
sanitizeTranslationItem()  : mixed
Sanitizes the submitted data-map for a particular item and removes fields which are not defined as custom and thus rely on either parent or source values.
synchronizeDirectRelations()  : void
Synchronize select and group field localizations
synchronizeFieldValues()  : mixed
Synchronize simple values like text and similar
synchronizeReferences()  : void
Handle synchronization of references (inline or file).
synchronizeTranslationItem()  : mixed
Synchronize a single item

Properties

$allDataMap

protected array $allDataMap = []

$modifiedDataMap

protected array<string, array> $modifiedDataMap = []

$sanitizationMap

protected array<string, array<int, array>> $sanitizationMap = []

Methods

process()

Processes the submitted data-map and returns the sanitized and enriched version depending on accordant localization states and dependencies.

public process() : array

Return values

array

applyLocalizationReferences()

Applies localization references to given raw data-map item.

protected applyLocalizationReferences(string $tableName, string|int $fromId, int $language, array $fieldNames, array $data) : array

Parameters

$tableName : string
$fromId : string|int
$language : int
$fieldNames : array
$data : array

Return values

array

buildElementAncestorIdMap()

Builds a map from ancestor ids to accordant localization dependents.

protected buildElementAncestorIdMap(array $fieldNames, array $elements) : array

The result of e.g. [5 => [6, 7]] refers to ids 6 and 7 being dependents (either used in parent or source field) of the ancestor with id 5.

Parameters

$fieldNames : array
$elements : array

Return values

array

collectItems()

Create data map items of all affected rows

protected collectItems(string $tableName, array $idValues) : void

Parameters

$tableName : string
$idValues : array

fetchDependencies()

Fetches translation dependencies for a given parent/source record ids.

protected fetchDependencies(string $tableName, int[]|string[] $ids) : array<int|string, array<string, array<int, DataMapItem>>>

Existing records in database:

  • [uid:5, l10n_parent=0, l10n_source=0, sys_language_uid=0]
  • [uid:6, l10n_parent=5, l10n_source=5, sys_language_uid=1]
  • [uid:7, l10n_parent=5, l10n_source=6, sys_language_uid=2]

Input $ids and their results:

  • [5] -> [DataMapItem(6), DataMapItem(7)] # since 5 is parent/source
  • [6] -> [DataMapItem(7)] # since 6 is source
  • [7] -> [] # since there's nothing

Parameters

$tableName : string
$ids : int[]|string[]

Return values

array<int|string, array<string, array<int, DataMapItem>>>

fetchDependentElements()

Fetch all elements that depend on given record id's in either their parent or source field for translatable tables or their origin field for non-translatable tables.

protected fetchDependentElements(string $tableName, array $ids, array $fieldNames) : array

Parameters

$tableName : string
$ids : array
$fieldNames : array

Tags

throws
InvalidArgumentException

Return values

array

fetchDependentIdMap()

Fetches dependent records that depend on given record id's in in either their parent or source field for translatable tables or their origin field for non-translatable tables and creates an id mapping.

protected fetchDependentIdMap(string $tableName, array $ids, int $desiredLanguage) : array

This method expands the search criteria by expanding to ancestors.

Existing records in database:

  • [uid:5, l10n_parent=0, l10n_source=0, sys_language_uid=0]
  • [uid:6, l10n_parent=5, l10n_source=5, sys_language_uid=1]
  • [uid:7, l10n_parent=5, l10n_source=6, sys_language_uid=2]

Input $ids and $desiredLanguage and their results:

  • $ids=[5], $lang=1 -> [5 => 6] # since 5 is source of 6
  • $ids=[5], $lang=2 -> [] # since 5 is parent of 7, but different language
  • $ids=[6], $lang=1 -> [] # since there's nothing
  • $ids=[6], $lang=2 -> [6 => 7] # since 6 has source 5, which is ancestor of 7
  • $ids=[7], $lang=* -> [] # since there's nothing

Parameters

$tableName : string
$ids : array
$desiredLanguage : int

Return values

array

fetchTranslationValues()

Fetches translation related field values for the items submitted in the data-map.

protected fetchTranslationValues(string $tableName, array $fieldNames, array $ids) : array

Parameters

$tableName : string
$fieldNames : array
$ids : array

Return values

array

filterNewItemIds()

Return only ids that don't have an item equivalent in $this->allItems.

protected filterNewItemIds(string $tableName, int[] $ids) : array

Parameters

$tableName : string
$ids : int[]

Return values

array

filterNumericIds()

Return only ids that are integer - so no "NEW..." values

protected filterNumericIds(string[]|int[] $ids) : int[]

Parameters

$ids : string[]|int[]

Return values

int[]

findItem()

See if an items is in item list and return it

protected findItem(string $tableName, string|int $id) : DataMapItem|null

Parameters

$tableName : string
$id : string|int

Return values

DataMapItem|null

finishTranslationItem()

Finishes a translation item by updating states to be persisted.

protected finishTranslationItem(DataMapItem $item) : mixed

Parameters

$item : DataMapItem

getFieldNamesForItemScope()

Field names we have to deal with

protected getFieldNamesForItemScope(DataMapItem $item, string $scope, bool $modified) : string[]

Parameters

$item : DataMapItem
$scope : string
$modified : bool

Return values

string[]

getFieldNamesToBeHandled()

Gets a list of field names which have to be handled. Basically this includes fields using allowLanguageSynchronization or l10n_mode=exclude.

protected getFieldNamesToBeHandled(string $tableName) : string[]

Parameters

$tableName : string

Return values

string[]

getLocalizationModeExcludeFieldNames()

Field names of TCA table with columns having l10n_mode=exclude

protected getLocalizationModeExcludeFieldNames(string $tableName) : string[]

Parameters

$tableName : string

Return values

string[]

getPrefixLanguageTitleFieldNames()

Field names of TCA table with columns having l10n_mode=prefixLangTitle

protected getPrefixLanguageTitleFieldNames(string $tableName) : array

Parameters

$tableName : string

Return values

array

isApplicable()

Determines whether the table can be localized and either has fields with allowLanguageSynchronization enabled or l10n_mode set to exclude.

protected isApplicable(string $tableName) : bool

Parameters

$tableName : string

Return values

bool

isReferenceField()

True if we're dealing with a reference field (either "inline" or "file")

protected isReferenceField(string $tableName, string $fieldName) : bool

Parameters

$tableName : string
$fieldName : string

Return values

bool —

TRUE if field is of type inline with foreign_table set

isRelationField()

True if we're dealing with a field that has foreign db relations

protected isRelationField(string $tableName, string $fieldName) : bool

Parameters

$tableName : string
$fieldName : string

Return values

bool —

True if field is type=group or select with foreign_table

isSetInDataMap()

Determines whether a combination of table name, id and field name is set in data-map. This method considers null values as well, that would not be considered by a plain isset() invocation.

protected isSetInDataMap(string $tableName, string|int $id, string $fieldName) : bool

Parameters

$tableName : string
$id : string|int
$fieldName : string

Return values

bool

mapRelationItemId()

Flatten array

protected mapRelationItemId(array $relationItems) : int[]

Parameters

$relationItems : array

Return values

int[]

modifyDataMap()

Applies modifications to the data-map, calling this method is essential to determine new data-map items to be process for synchronizing chained record localizations.

protected modifyDataMap(string $tableName, string|int $id, array $values) : void

Parameters

$tableName : string
$id : string|int
$values : array

Tags

throws
RuntimeException

populateTranslationItem()

Populates values downwards, either from a parent language item or a source language item to an accordant dependent translation item.

protected populateTranslationItem(DataMapItem $item) : mixed

Parameters

$item : DataMapItem

prefixLanguageTitle()

Prefixes language title if applicable for the accordant field name in raw data-map item.

protected prefixLanguageTitle(string $tableName, string|int $fromId, int $language, array $data) : array

Parameters

$tableName : string
$fromId : string|int
$language : int
$data : array

Return values

array

purgeDataMap()

Purges superfluous empty data-map sections.

protected purgeDataMap(array $dataMap) : array

Parameters

$dataMap : array

Return values

array

resolveAncestorId()

protected resolveAncestorId(array<string, string> $fieldNames, array<string, mixed> $element) : int|null

Parameters

$fieldNames : array<string, string>
$element : array<string, mixed>

Return values

int|null —

either a (non-empty) ancestor uid, or null if unresolved

resolveSuggestedInlineRelations()

Determines suggest inline relations of either translation parent or source record from data-map or storage in case records have been persisted already.

protected resolveSuggestedInlineRelations(DataMapItem $item, string $fieldName, array $fromRecord) : int[]|string[]

Parameters

$item : DataMapItem
$fieldName : string
$fromRecord : array

Return values

int[]|string[]

sanitize()

Sanitizes the submitted data-map items and removes fields which are not defined as custom and thus rely on either parent or source values.

protected sanitize(DataMapItem[] $items) : mixed

Parameters

$items : DataMapItem[]

sanitizeTranslationItem()

Sanitizes the submitted data-map for a particular item and removes fields which are not defined as custom and thus rely on either parent or source values.

protected sanitizeTranslationItem(DataMapItem $item) : mixed

Parameters

$item : DataMapItem

synchronizeDirectRelations()

Synchronize select and group field localizations

protected synchronizeDirectRelations(DataMapItem $item, string $fieldName, array $fromRecord) : void

Parameters

$item : DataMapItem
$fieldName : string
$fromRecord : array

synchronizeFieldValues()

Synchronize simple values like text and similar

protected synchronizeFieldValues(DataMapItem $item, string $fieldName, array $fromRecord, array $forRecord) : mixed

Parameters

$item : DataMapItem
$fieldName : string
$fromRecord : array
$forRecord : array

synchronizeReferences()

Handle synchronization of references (inline or file).

protected synchronizeReferences(DataMapItem $item, string $fieldName, array $fromRecord, array $forRecord) : void

References are always modelled as 1:n composite relation - which means that direct(!) children cannot exist without their parent. Removing a relative parent results in cascaded removal of all direct(!) children as well.

Parameters

$item : DataMapItem
$fieldName : string
$fromRecord : array
$forRecord : array

Tags

throws
RuntimeException

synchronizeTranslationItem()

Synchronize a single item

protected synchronizeTranslationItem(DataMapItem $item, array $fieldNames, string|int $fromId) : mixed

Parameters

$item : DataMapItem
$fieldNames : array
$fromId : string|int
On this page