SelectItemProcessor
Provides shared select item related utility functions.
ext:backend internal implementation and not part of the public core API.
Tags
Attributes
- #[Autoconfigure]
- $public: true
Table of Contents
Properties
Methods
- __construct() : mixed
- groupAndSortItems() : array<string|int, mixed>
- Is used when --div-- elements in the item list are used, or if groups are defined via "groupItems" config array.
- transformArrayToSelectItems() : array<string|int, SelectItem>
- transformSelectItemsToArray() : array<string|int, mixed>
- sortItems() : array<string|int, SelectItem>
- Sort given items by label or value or a custom user function built like "MyVendor\MyExtension\TcaSorter->sortItems" or a callable.
Properties
$languageServiceFactory read-only
protected
LanguageServiceFactory
$languageServiceFactory
Methods
__construct()
public
__construct(LanguageServiceFactory $languageServiceFactory) : mixed
Parameters
- $languageServiceFactory : LanguageServiceFactory
groupAndSortItems()
Is used when --div-- elements in the item list are used, or if groups are defined via "groupItems" config array.
public
groupAndSortItems(array<string|int, mixed> $allItems, array<string|int, mixed> $definedGroups, array<string|int, mixed> $sortOrders) : array<string|int, mixed>
This method takes the --div-- elements out of the list, and adds them to the group lists.
A main "none" group is added, which is always on top, when items are not set to be in a group. All items without a groupId - which is defined by the fourth key of an item in the item array - are added to the "none" group, or to the last group used previously, to ensure ordering as much as possible as before.
Then the found groups are iterated over the order in the [itemGroups] list, and items within a group can be sorted via "sortOrders" configuration.
All grouped items are then "flattened" out and --div-- items are added for each group to keep backwards-compatibility.
Parameters
- $allItems : array<string|int, mixed>
-
all resolved items including the ones from foreign_table values. The group ID information can be found in key ['group'] of an item.
- $definedGroups : array<string|int, mixed>
-
[config][itemGroups]
- $sortOrders : array<string|int, mixed>
-
[config][sortOrders]
Return values
array<string|int, mixed>transformArrayToSelectItems()
public
transformArrayToSelectItems(array<string|int, mixed> $items[, string $type = 'select' ]) : array<string|int, SelectItem>
Parameters
- $items : array<string|int, mixed>
- $type : string = 'select'
Return values
array<string|int, SelectItem>transformSelectItemsToArray()
public
transformSelectItemsToArray(array<string|int, mixed> $items) : array<string|int, mixed>
Parameters
- $items : array<string|int, mixed>
Return values
array<string|int, mixed>sortItems()
Sort given items by label or value or a custom user function built like "MyVendor\MyExtension\TcaSorter->sortItems" or a callable.
protected
sortItems(array<string|int, SelectItem> $items, array<string|int, mixed> $sortOrders) : array<string|int, SelectItem>
Parameters
- $items : array<string|int, SelectItem>
- $sortOrders : array<string|int, mixed>
-
should be something like like [label => desc]
Return values
array<string|int, SelectItem> —the sorted items