DataMapProcessor
class \
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
Internal
should only be used by the TYPO3 Core
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
- __construct() : mixed
- 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() : mixed
- applyLocalizationReferences() : array
- Applies localization references to given raw data-map item.
- buildElementAncestorIdMap() : array
- Builds a map from ancestor ids to accordant localization dependents.
- collectItems() : mixed
- Create data map items of all affected rows
- createRelationHandler() : RelationHandler
- enrich() : mixed
- Handle synchronization of an item list
- fetchDependencies() : 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
- 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() : string[]
- Flatten array
- modifyDataMap() : mixed
- 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() : mixed
- Synchronize select and group field localizations
- synchronizeFieldValues() : mixed
- Synchronize simple values like text and similar
- synchronizeReferences() : mixed
- Handle synchronization of references (inline or file).
- synchronizeTranslationItem() : mixed
- Synchronize a single item
Properties
$allDataMap
protected
array
$allDataMap
= []
$allItems
protected
DataMapItem[]
$allItems
= []
$backendUser
protected
BackendUserAuthentication
$backendUser
$modifiedDataMap
protected
array<string, array>
$modifiedDataMap
= []
$nextItems
protected
DataMapItem[]
$nextItems
= []
$referenceIndexUpdater
protected
ReferenceIndexUpdater
$referenceIndexUpdater
$sanitizationMap
protected
array<string, array<int, array>>
$sanitizationMap
= []
Methods
__construct()
public
__construct(array $dataMap, BackendUserAuthentication $backendUser[, ReferenceIndexUpdater|null $referenceIndexUpdater = null ]) : mixed
Parameters
- $dataMap : array
-
The submitted data-map to be worked on
- $backendUser : BackendUserAuthentication
-
Forwarded backend-user scope
- $referenceIndexUpdater : ReferenceIndexUpdater|null = null
-
Forward reference index updater to sub DataHandler instances
instance()
Class generator
public
static instance(array $dataMap, BackendUserAuthentication $backendUser[, ReferenceIndexUpdater|null $referenceIndexUpdater = null ]) : DataMapProcessor
Parameters
- $dataMap : array
-
The submitted data-map to be worked on
- $backendUser : BackendUserAuthentication
-
Forwarded backend-user scope
- $referenceIndexUpdater : ReferenceIndexUpdater|null = null
-
Forward reference index updater to sub DataHandler instances
Return values
DataMapProcessorprocess()
Processes the submitted data-map and returns the sanitized and enriched version depending on accordant localization states and dependencies.
public
process() : array
Return values
arrayaddNextItem()
protected
addNextItem(DataMapItem $item) : mixed
Parameters
- $item : DataMapItem
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
arraybuildElementAncestorIdMap()
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
arraycollectItems()
Create data map items of all affected rows
protected
collectItems(string $tableName, array $idValues) : mixed
Parameters
- $tableName : string
- $idValues : array
createRelationHandler()
protected
createRelationHandler() : RelationHandler
Return values
RelationHandlerenrich()
Handle synchronization of an item list
protected
enrich(DataMapItem[] $items) : mixed
Parameters
- $items : DataMapItem[]
fetchDependencies()
Fetches translation dependencies for a given parent/source record ids.
protected
fetchDependencies(string $tableName, int[]|string[] $ids) : 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
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
Return values
arrayfetchDependentIdMap()
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
arrayfetchTranslationValues()
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
arrayfilterItemsByType()
Return array of data map items that are of given type
protected
filterItemsByType(string $type, DataMapItem[] $items) : DataMapItem[]
Parameters
- $type : string
- $items : DataMapItem[]
Return values
DataMapItem[]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
arrayfilterNumericIds()
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|nullfinishTranslationItem()
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[]getLanguageService()
protected
getLanguageService() : LanguageService|null
Return values
LanguageService|nullgetLocalizationModeExcludeFieldNames()
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
arrayisApplicable()
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
boolisReferenceField()
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
boolmapRelationItemId()
Flatten array
protected
mapRelationItemId(array $relationItems) : string[]
Parameters
- $relationItems : array
Return values
string[]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) : mixed
Parameters
- $tableName : string
- $id : string|int
- $values : array
Tags
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
arraypurgeDataMap()
Purges superfluous empty data-map sections.
protected
purgeDataMap(array $dataMap) : array
Parameters
- $dataMap : array
Return values
arrayresolveAncestorId()
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) : mixed
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) : mixed
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
synchronizeTranslationItem()
Synchronize a single item
protected
synchronizeTranslationItem(DataMapItem $item, array $fieldNames, string|int $fromId) : mixed
Parameters
- $item : DataMapItem
- $fieldNames : array
- $fromId : string|int