Reflection Service

Service class for converting complex objects to a simple array structure based of TCA configuration. Handy for faster integration development, headless systems and ajax calls.

class Jar\Utilities\Services\ReflectionService

Configuration

Tip

For column definitions, you can use wildcards like "?" and "*". So instead of define table_class, table_caption, table_delimiter, table_enclosure, ... specificly, you can use table_*.

setPropertiesByConfigurationArray($configuration)

Sets multiple properties in one call.

Parameters
  • $configuration (array) -- Configuration settings.

Returns

self

Example:

setPropertiesByConfigurationArray([
   'tableColumnBlacklist' => [
      // don't reflect the "categories" column in tx_myextension_slides
      'tx_myextension_slides' => 'categories',
      // don't reflect the "doktype" column and all columns
      // starting with "cache_" in pages
      'pages' => 'cache_*, doktype'
   ],
   'tableColumnWhitelist' => [
      // just reflect the slide related fields and the header in tt_content
      'tt_content' => 'tx_myextension_*, header'
   ],
   'tableColumnRemoveablePrefixes' => [
      // remove the prefix "tx_myextension_" from our columns
      'tt_content' => 'tx_myextension_'
   ],
   'tableColumnRemapping' => [
      'tt_content' => [
         // rename the column "header" to "title" in the result
         'header' => 'title'
      ]
   ],
   'buildingConfiguration' => [
      // ... same settings like "setBuildingConfiguration" (example below)
   ],
   // deactivate debug output of reflection
   'debug' => false,
]);

Attention

In comparison to the direct using of setter-methods, some table-handle-definitions are commaseparated. This affects the setting for tableColumnBlacklist, tableColumnWhitelist and tableColumnRemoveablePrefixes.

setColumnBlacklist($columnBlacklist)

Set list of columns that are generally not processed. This blacklist will be applied to every table.

Parameters
  • $columnBlacklist (array) -- List of columns that are generally not processed.

Returns

self

Example:

setColumnBlacklist([
   't3ver_*',
   'l18n_*',
   'l10n_*',
   'crdate',
   'cruser_id',
   'editlock',
   /* ... */
]);
setTableColumnBlacklist($columnBlacklist)

Set list of table specific columns which aren't processed.

Parameters
  • $tableColumnBlacklist (array) -- List of table specific columns which aren't processed.

Returns

self

Example:

setTableColumnBlacklist([
   // don't reflect the "categories" column in tx_myextension_slides
   'tx_myextension_slides' => ['categories'],
   // don't reflect the "doktype" column and all columns
   // starting with "cache_" in pages
   'pages' => ['cache_*', 'doktype']
]);
addToTableColumnBlacklist($tableColumnBlacklist)

Add to list of table specific columns which aren't processed. Same as setTableColumnBlacklist without replacing the whole tableColumnBlacklist-Settings

Parameters
  • $tableColumnBlacklist (array) -- List of table specific columns which aren't processed.

Returns

self

setTableColumnWhitelist($tableColumnWhitelist)

Set List of tables columns which should be processed exclusively.

Parameters
  • $tableColumnWhitelist (array) -- List of tables columns which should be processed exclusively.

Returns

self

Example:

setTableColumnWhitelist([
   // just reflect the slide related fields and the header in tt_content
   'tt_content' => ['tx_myextension_*', 'header']
]);
setTableColumnRemoveablePrefixes($tableColumnRemoveablePrefixes)

Set wildcard based replacement for column names. F.e. 'tt_content' => ['table_'] converts 'tt_content->table_caption' to 'tt_content->caption'

Parameters
  • $tableColumnRemoveablePrefixes (array) -- Wildcard based replacement for column names.

Returns

self

Example:

setTableColumnRemoveablePrefixes([
   // remove the prefix "tx_myextension_" from our columns
   'tt_content' => ['tx_myextension_']
]);
setTableColumnRemapping($tableColumnRemapping)
Set remap column-names in reflected result. F.e. 'tt_content' => ['table_caption' => 'heading'] converts 'tt_content->table_caption' to 'tt_content->heading'.

Important: takes action AFTER replacement of ColumnNames! Keep that in mind.

Parameters
  • $tableColumnRemapping (array) -- Remapping definition list.

Returns

self

Example:

setTableColumnRemapping([
   'tt_content' => [
      // rename the column "header" to "title" in the result
      'header' => 'title'
   ]
]);
setBuildingConfiguration($arrayBuildingConfiguration)

Contains e.g. instructions for the preparation of files and images.

Parameters
  • $arrayBuildingConfiguration (array) -- Instructions for the preparation of files and images.

Returns

self

Example:

setBuildingConfiguration([
   'file' => [
      // we don't want deeper informations about files (f.e. filename,
      // extension, size, etc ..)
      'showDetailedInformations' => false,
      // set image rendering instructions for the different cropping variants
      'processingConfigurationForCrop' => [
         'desktop' => [
            'maxWidth' => 3000
         ],
         'medium' => [
            'maxWidth' => 1920
         ],
         'tablet' => [
            'maxWidth' => 1024
         ],
         'mobile' => [
            'maxWidth' => 920
         ]
      ]
   ]
]);

Reflection output

buildArrayByRows($rows, $table, $maxDepth)

Reflects a list of record rows.

Parameters
  • $rows (array) -- The record list.

  • $table (string) -- The tablename.

  • $maxDepth (int) -- The maximum depth at which related elements are loaded (default is 8).

Returns

Reflected result.

buildArrayByRow($rows, $table, $maxDepth)

Reflects a single record row.

Parameters
  • $row (array) -- The record row.

  • $table (string) -- The tablename.

  • $maxDepth (int) -- The maximum depth at which related elements are loaded (default is 8).

Returns

Reflected result.

Tip

For examples output, take a look into Reflection Processor example or Reflected TCA field output examples


Getter

getTcaFieldDefinition()

Get array for used TCA field definitions, helpful for Post-handling that prepared data.

Returns

All used TCA table and column definitions which was used on the last reflection.

Note

For each configration-Setter above there is also a getter available (f.e. setColumnBlacklist / getColumnBlacklist). For the sake of clarity, these are not listed here.


Reflected TCA field output examples

Reflected records are builded from the following elements.

Flat fields:

Password (TCA field with eval password)

Input

password12345

Output

Nothing, for security reasons, we don't reflect password fields.



Time (TCA type input with renderType inputDateTime and eval time)

Input

62880

Output
[
   'timeForSorting' => 62880,
   'formatedTime' => '17:28'
]


DateTime (TCA type input with renderType inputDateTime and eval datetime or date)

Input

2021-08-25 13:31:00

Output
[
   'unix' => 1629898260,
   'day' => '25',
   'dayNonZero' => '25',
   'weekDayText' => 'Mittwoch',
   'weekDayTextShort' => 'Mi',
   'month' => '08',
   'monthText' => 'August',
   'monthTextShort' => 'Aug',
   'year' => '2021',
   'hour' => '13',
   'minute' => '31',
   'second' => '00',
   'dateForSorting' => '2021-08-25',
   'formatedDate' => '25.08.2021',
   'formatedDateShort' => '25.08.21',
   'formatedDateShorter' => '25.08.',
   'dayOfWeek' => '3',
   'weekOfYear' => '34',
   'formatedTime' => '13:31',
]

Note

The example above shows german weekdays and months, this generation is based on the current active language



Textarea (TCA type text and enableRichtext is false)

Input
Hello
World
Output
Hello<br />World


RTE (TCA type text and enableRichtext is true)

Input
<h1>Lorem Ipsum</h1><p><a href="t3://page?uid=123">Click me</a></p>
Output
<h1>Lorem Ipsum</h1><p><a href="/a-page">Click me</a></p>


Checkbox (TCA type check)

Output

true when checked, otherwise false.



Others (TCA type radio, passthrough, slug and flex)

Output

The raw field value.

Note

Also all unknown types of flat fields are returned raw.



Relation fields:

Files and Images (TCA -mostly- type inline and foreign_table is sys_file_reference)

Input

Sum of references. The linked records will be resolved via TCA config.

Output
[
   [
      'uid' => 1
      'url' => 'fileadmin/user_upload/my-image-original.jpg',
      'alt' => 'some text',
      'title' => 'some text',
      'description' => 'some text',
      'link' => NULL,
      // 'cropped' is just available for image-files
      'cropped' => [
         'desktop' => 'fileadmin/_processed_/1/my-image-original-max-width-3000.jpg',
         'medium' => 'fileadmin/_processed_/1/my-image-original-max-width-1920.jpg',
         'tablet' => 'fileadmin/_processed_/1/my-image-original-max-width-1024.jpg',
         'mobile' => 'fileadmin/_processed_/1/my-image-original-max-width-920.jpg'
      ]
   ],
   /* maybe more images ... */
]


Other relations that file (TCA type inline, select, group)

Input

Sum of references. The linked records will be resolved via TCA config.

Output

Each related element will be resolved in an array of this structure of his flat elements and relations.