Utility classes that simplify TYPO3 development. We have been developing TYPO3 projects for over 10 years using the same little helpers repeatedly.
Now we outsourced these helpers in an own extension to offer all TYPO3 developers a faster and easier way to develop their extensions as well.
TYPO3
The content of this document is related to TYPO3 CMS,
a GNU/GPL CMS/Framework available from typo3.org .
Extension Manual
This documentation is for the TYPO3 extension jar_utilities.
Serving a collection of PHP Utilities and TypoScript DataProcessors for faster TYPO3 Extension Development
What problems does it solve?
Simplifies "daily-business Tasks" starting from formating RTE-Content and ends with loading data from content including related elements in a headless-friendly structure
Who is the target audience?
TYPO3 Integrator and Developer
Installation
Installation Type
Composer
You can install jar_utilities with following shell command:
composer req jar/jar_utilities
Copied!
Extensionmanager
If you want to install jar_utilities traditionally with Extensionmanager, follow these steps:
tt_content.tx_myextension_joblistctype {
dataProcessing {
10 = TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor
10 {
table = tx_myextension_jobs
pidInList = 266
as = jobs
dataProcessing {
10 = Jar\Utilities\DataProcessing\LinkProcessor
10 {
page = 187
title = TEXT
title.data = field:title
as = detail_link
params {
jobid = TEXT
jobid.data = field:uid
}
}
}
}
}
}
Copied!
Localization Processor
Add translations directly to the template - this gives frontenders faster handling of the translation variables
Attention
Just the _LOCAL_LANG TypoScript Configuration could be loaded with this Processor, if you want to load translations from files, please use the proper ViewHelpers!
Parameter
Description
extensionsToLoad
Commaseparated list of extension-keys
flat
If active, all translations of all translations will be outputed in one resulting list, otherwise the translations would be grouped by extension key
Tip
Activating is useful, when you just want to load translations from one extension
as
If set, the result would be stored in this key, otherwise the result-fields will directly be merged in the data(!)
TypoScript wrapper for Reflection Service. Maps data to a simple array structure, based on the TCA configuration of the table. Also resolves all TCA-relations to other tables.
The strength lies in the fast loading of already existing structures, especially when using Ajax requests or headless systems.
Parameter
Description
buildingConfiguration
Contains e.g. instructions for the preparation of files and images (see Example Case).
debug
var_dumps information which elements would be reflected.
maxDepth
The maximum depth at which related elements are loaded (default is 8).
replace
Replace the current data with the result of this DataProcessor
row
If set, data content of row would be reflected, otherwise the current data would be used (default).
rows
Same behavior as using row, with one important difference:
To guard against endless recursions and unperformant reloading of rows, the Reflection service uses an internal store for previously loaded elements.
This is store is accessable for all elements in rows. This is a huge performance gain, especially when the elements in rows are often related to the same elements.
Note
Load order
rows
row
current data
table
Tablename which should be mapped (default: tt_content) (see Example Case).
tableColumnBlacklist
List of table columns which should be blacklisted (wildcards like "*" and "?" are useable) (see Example Case).
Note
You don't need to blacklist core-related columns like 't3ver_oid', 't3_origuid', etc. The Reflection Service will filter them out. The 'uid' column can't be blacklisted
tableColumnRemapping
List of table columns to be renamed (see Example Case)
tableColumnRemoveablePrefixes
List of table columns where the prefix should be removed (see Example Case)
tableColumnWhitelist
List of table columns which should be whitelisted (wildcards like "*" and "?" are useable) (see Example Case)
Example Case
Assuming we have want to reflect of an slider element with the following table column / TCA structure:
CType "slider" (located in table tt_content)
all default tt_content fields (header, categories, space_before_class, etc ...)
tx_myextension_duration (input, with eval "int")
tx_myextension_slides (IRRE relation to table tx_myextension_slides)
image (FAL with the croppings for desktop, medium, tablet, mobile)
headline (input)
descrition (RTE text)
link (input with link wizard)
categories (category tree)
Output before reflection
[
'data' => [
'uid' => 123,
'pid' => 345,
'categories' => 4,
'header' => 'my slider',
'tx_myextension_duration' => 8000,
'tx_myextension_slides' = 3// ... many other system related columns
],
'current' => null
]
Copied!
Reflecting of related data
Attention
Don't reflect (tt_content) elements without black- or whitelisting! Every relation (including every sub-relation) would be resolved!
tt_content.slider.dataProcessing {
10 = Jar\Utilities\DataProcessing\ReflectionProcessor
10 {
# FYI: this is superfluous, because "tt_content" is the default value
table = tt_content
tableColumnWhitelist {
# just reflect the slide related fields and the header in tt_content
tt_content = tx_myextension_*, header
}
tableColumnBlacklist {
# don't reflect the "categories" column in tx_myextension_slides
tx_myextension_slides = categories
}
tableColumnRemapping {
tt_content {
# rename the column "header" to "title" in the result
header = title
}
}
tableColumnRemoveablePrefixes {
# remove the prefix "tx_myextension_" from our columns
tt_content = tx_myextension_
}
buildingConfiguration {
file {
# we don't want deeper informations about files (f.e. filename, extension, size, etc ..)
showDetailedInformations = 0
# set image rendering instructions for the different cropping variants
processingConfigurationForCrop {
desktop.maxWidth = 3000
medium.maxWidth = 1920
tablet.maxWidth = 1024
mobile.maxWidth = 920
}
}
}
}
}
Copied!
Tip
In most cases buildingConfiguration it's helpful to outsource to an globaly place like an lib-object
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.
classReflectionService
Fully qualified name
\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.
param array $configuration
Configuration settings.
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,
]);
Copied!
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.
Returns
self
setColumnBlacklist($columnBlacklist)
Set list of columns that are generally not processed.
This blacklist will be applied to every table.
Set list of table specific columns which aren't processed.
param array $tableColumnBlacklist
List of table specific columns which aren't processed.
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']
]);
Copied!
Returns
self
addToTableColumnBlacklist($tableColumnBlacklist)
Add to list of table specific columns which aren't processed.
Same as setTableColumnBlacklist without replacing the whole tableColumnBlacklist-Settings
param array $tableColumnBlacklist
List of table specific columns which aren't processed.
Returns
self
setTableColumnWhitelist($tableColumnWhitelist)
Set List of tables columns which should be processed exclusively.
param array $tableColumnWhitelist
List of tables columns which should be processed exclusively.
Example:
setTableColumnWhitelist([
// just reflect the slide related fields and the header in tt_content'tt_content' => ['tx_myextension_*', 'header']
]);
Set wildcard based replacement for column names.
F.e. 'tt_content' => ['table_'] converts 'tt_content->table_caption' to 'tt_content->caption'
param array $tableColumnRemoveablePrefixes
Wildcard based replacement for column names.
Example:
setTableColumnRemoveablePrefixes([
// remove the prefix "tx_myextension_" from our columns'tt_content' => ['tx_myextension_']
]);
Copied!
Returns
self
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.
param array $tableColumnRemapping
Remapping definition list.
returns
self
Example:
setTableColumnRemapping([
'tt_content' => [
// rename the column "header" to "title" in the result'header' => 'title'
]
]);
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.
|
Link (TCA type input with renderType inputLink)
Input
t3://page?uid=196 _blank warning "Click me" ?bla=1
Get route link for editing records in backend. Wrapped in a <a>-Tag
param string $table
The record table.
param int $uid
The record uid.
param string $content
Inner HTML of the <a>-tag.
Example:
BackendUtility::getWrappedEditLink('tt_content', 123, 'Click to edit');
Copied!
returns
<ahref="/typo3/index.php?route=%2Frecord%2Fedit&token=...">Click to edit</a>
Copied!
Returns
The resulting <a>-tag.
getWizardInformations($ctype)
Returns informations from the "New Content Wizard".
param string $ctype
The CType.
Example:
BackendUtility::getWizardInformations('html');
Copied!
returns
[
'iconIdentifier' => 'content-special-html',
'title' => 'Plain HTML',
'description' => 'With this element you can insert raw HTML code on the page.'
]
Shorthand for FileUtility::buildFileArrayBySysFileReference(FileUtility::getFileReferenceByUid($uid)), accepts the UID of an FileReference instead of using the FileReference object directly.
Preparation of files and images in a simple array structure. Very helpful in image preparation and cropping.
param \TYPO3\CMS\Core\Resource\FileReference
$fileReference
param array $configuration
(optional). The configuration is based on three settings:
1. showDetailedInformations (bool): For all kind of files. If active, list more informations about the file (name, extension, type, mimetype, size, basename).
Warning
This has an noticeable impact on performance when a huge amount of files is processed.
2. tcaCropVariants (array): Just for images. List of -, which are applied to the images.
Tip
Instead of putting this together yourself, it's easier to use the Reflection Service or Reflection Processor. These automatically read the tcaCropVariants from the corresponding TCA configurations of the images.
3. processingConfigurationForCrop (array): Just for images. Configuration how the image should be proceed in the different tcaCropVariants. Configurations like maxWidth, minWidth, width (applies also for heigth) are possible.
Example:
FileUtility::buildFileArrayBySysFileReference(
$aFileReference,
[
// show informations about file'showDetailedInformations' => true,
// set cropping variants'tcaCropVariants' => [
'desktop' => [
/* .. */'cropArea' => [
'x' => 0.0,
'y' => 0.0,
'width' => 1.0,
'height' => 1.0,
]
],
'mobile' => [
/* .. */'cropArea' => [
'x' => 0.0,
'y' => 0.0,
'width' => 1.0,
'height' => 1.0,
]
]
],
// set image rendering instructions for the different cropping variants 'processingConfigurationForCrop' => [
'desktop' => [
'maxWidth' => 3000
],
// will be ignored, because we have no tcaCropVariants['medium'] informations'medium' => [
'maxWidth' => 1920
],
// will be ignored, because we have no tcaCropVariants['tablet'] informations'tablet' => [
'maxWidth' => 1024
],
'mobile' => [
'maxWidth' => 920
]
]
]
);
Copied!
returns
[
// base informations'uid' => 1'url' => 'fileadmin/user_upload/my-image-original.jpg',
'alt' => 'some text',
'title' => 'some text',
'description' => 'some text',
'link' => NULL,
// detailed informations'name' => 'my-image-original.jpg',
'extension' => 'jpg',
'type' => 2,
'mimetype' => 'image/jpeg',
'size' => 2313,
'basename' => 'my-image-original',
// 'cropped' is just available for image-files'cropped' => [
'desktop' => 'fileadmin/_processed_/1/my-image-original-max-width-3000.jpg',
'mobile' => 'fileadmin/_processed_/1/my-image-original-max-width-920.jpg'
]
// if the extension "focuspoint" is installed, you also get the following properties'has_focuspoint' => true,
'focuspoint' => [
'x' => 0.1,
'y' => 0.2,
'w' => 0.3,
'h' => 0.4
]
]
Copied!
Returns
File-information array or null if resource doesn't exist or file is missing.
buildFileArrayByFile($file, $configuration)
Same as buildFileArrayBySysFileReference based on a file object
Slides up a the Pagetree (starting from the current page) and return the nearest filled value of the field.
param string $fieldname
Name of the field/column.
Returns
Value of the field when found, otherwise "null".
String Utility
Collection of string helpers.
classStringUtility
Fully qualified name
\Jar\Utilities\Utilities\StringUtility
crop($value, int $maxCharacters = 150)
Crops a string.
param string $value
The string to crop.
param int $maxCharacters
Length of cropping.
Example:
var_dump(StringUtility::crop('Lorem ipsum dolor sit amet.', 20));
// 'Lorem ipsum dolor...'// Respects also crops in Tags
var_dump(StringUtility::crop('<h1>Lorem ipsum dolor sit.</h1>', 20));
// '<h1>Lorem ipsum dolor...</h1>'
Copied!
Returns
The cropped string.
ripTags($string)
Same as "strip_tags" but leaves spaces at the position of removed tags.
Simple sanitizing of strings, no complex handling of umlauts like "äöü".
param string $string
The string to sanitize.
param bool $toLowerCase
Should the string converted to lower case?
Example:
var_dump(StringUtility::fastSanitize('Über wie viele Brücken musst du gehen?', true));
// 'ber_wie_viele_br_cken_musst_du_gehen'
var_dump(StringUtility::fastSanitize('Über wie viele Brücken musst du gehen?', false));
// 'ber_wie_viele_Br_cken_musst_du_gehen'
Copied!
Returns
The sanitized string.
sanitize($string, $toLowerCase = true)
More complex sanitizing of strings, also handles of umlauts like "äöü".
param string $string
The string to sanitize.
param bool $toLowerCase
Should the string converted to lower case?
Example:
var_dump(StringUtility::sanitize('Über wie viele Brücken musst du gehen?', true));
// 'ueber_wie_viele_bruecken_musst_du_gehen'
var_dump(StringUtility::sanitize('Über wie viele Brücken musst du gehen?', false));
// 'UEber_wie_viele_Bruecken_musst_du_gehen'
Converts a comma-separated list of TCA Columns (a,b,c) to [a,b,c]. Also columns of containing pallets will be resolved (if parameter table is available).
param string $list
Comma-separated list of TCA Columns.
param string $table
The table name.
param bool $extendedList
Flag for returning extendedList.
Returns
List of column names or list of [column name | label] when $extendedList is active.
getFieldDefinition($table, $column, $type = null)
Returns the current TCA field definition from a table column. Also resolves column overrides when parameter "type" is set.
param string $table
The table name.
param string $column
The column name.
param null|string $type
The type to respect column overrides.
Returns
The field definition or "null" when no field definition is found.
getFieldConfig($table, $column, $type = null)
Returns the TCA field configuration from a table column.
param string $table
The table name.
param string $column
The column name.
param null|string $type
The type to respect column overrides.
Returns
The field configuration or "null" when no field configuration is found.
Resolves cObjects and leaves values without deeper configuration as they are
param array $conf
Plain TypoScript array.
param null|ContentObjectRenderer $cObj
ContentObject which should be used.
Example:
# converts this typoscript array from ...
hello = world
element = TEXT
element.value = Bla
tree.value = Blupp
# ... to this:
hello = world
element = Bla
tree.value = Blupp
Copied!
Returns
The plain populated TypoScript array.
Wildcard Utility
Utility Class for handling wildcard opertations like "b?a_*"