ExtensionManagementUtility
Extension Management functions
This class is never instantiated, rather the methods inside is called as functions like \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('my_extension');
Table of Contents
Properties
Methods
- addFieldsToAllPalettesOfField() : void
- Adds new fields to all palettes that is defined after an existing field.
- addFieldsToPalette() : void
- Adds new fields to a palette.
- addFieldsToUserSettings() : void
- Adds a list of new fields to the TYPO3 USER SETTINGS configuration "showitem" list, the array with the new fields itself needs to be added additionally to show up in the user setup, like $GLOBALS['TYPO3_USER_SETTINGS']['columns'] += $tempColumns
- addPiFlexFormValue() : void
- Adds an entry to the "ds" array of the tt_content field "pi_flexform".
- addPlugin() : void
- This is a helper method to add a new "frontend plugin". It therefore takes the $itemArray (label, value[,icon]) and adds to the items-array of $GLOBALS['TCA']['tt_content']['columns']['CType'|. So basically, this method adds a new "select item" to the tt_content record type column ("CType").
- addRecordType() : void
- Convenience method so you don't have to deal with strings and arrays and $GLOBALS[TCA] directly that much.
- addService() : void
- Adds a service to the global services array
- addStaticFile() : void
- Call this method to add an entry in the static template list found in sys_templates FOR USE IN Configuration/TCA/Overrides/sys_template.php Use in ext_tables.php may break the frontend.
- addTCAcolumns() : void
- Adding fields to an existing table definition in $GLOBALS['TCA'] Adds an array with $GLOBALS['TCA'] column-configuration to the $GLOBALS['TCA']-entry for that table.
- addTcaSelectItem() : void
- Add an item to a select field item list.
- addTcaSelectItemGroup() : void
- Adds an item group to a TCA select field, allows to add a group so addTcaSelectItem() can add a groupId with a label and its position within other groups.
- addToAllTCAtypes() : void
- Makes fields visible in the TCEforms, adding them to the end of (all) "types"-configurations
- addToInsertRecords() : void
- Adds the $table tablename to the list of tables allowed to be includes by content element type "Insert records" By using $content_table and $content_field you can also use the function for other tables.
- addTypoScript() : void
- Adds $content to the default TypoScript code for either setup or constants as set in $GLOBALS['TYPO3_CONF_VARS'][FE]['defaultTypoScript_*'] (Basically this function can do the same as addTypoScriptSetup and addTypoScriptConstants - just with a little more hazzle, but also with some more options!) FOR USE IN ext_localconf.php FILES Note: As of TYPO3 CMS 6.2, static template #43 (content: default) was replaced with "defaultContentRendering" which makes it possible that a first extension like fluid_styled_content registers a "contentRendering" template (= a template that defines default content rendering TypoScript) by adding itself to $TYPO3_CONF_VARS[FE][contentRenderingTemplates][] = 'myext/Configuration/TypoScript'.
- addTypoScriptConstants() : void
- Adds $content to the default TypoScript constants code as set in $GLOBALS['TYPO3_CONF_VARS'][FE]['defaultTypoScript_constants'] NOT prefixed with a [GLOBAL] line, other calls MUST properly close their conditions! FOR USE IN ext_localconf.php FILES
- addTypoScriptSetup() : void
- Adds $content to the default TypoScript setup code as set in $GLOBALS['TYPO3_CONF_VARS'][FE]['defaultTypoScript_setup'].
- deactivateService() : void
- Deactivate a service
- extPath() : string
- Returns the absolute path to the extension with extension key $key.
- findService() : array<string|int, mixed>|false
- Find the available service with highest priority
- findServiceByKey() : array<string|int, mixed>
- Find a specific service identified by its key Note that this completely bypasses the notions of priority and quality
- getCN() : string
- Returns the correct class name prefix for the extension key $key
- getExtensionVersion() : string
- Retrieves the version of an installed extension.
- getLoadedExtensionListArray() : array<string|int, mixed>
- Gets an array of loaded extension keys
- isLoaded() : bool
- Returns TRUE if the extension with extension key $key is loaded.
- isServiceAvailable() : bool
- Check if a given service is available, based on the executable files it depends on
- loadExtension() : void
- Loads given extension
- registerPageTSConfigFile() : void
- Call this method to add an entry in the page TSconfig list found in pages FOR USE in Configuration/TCA/Overrides/pages.php
- resolvePackagePath() : string
- Temporary helper method to resolve paths with the PackageManager.
- setPackageManager() : void
- Sets the package manager for all that backwards compatibility stuff, so it doesn't have to be fetched through the bootstrap.
- unloadExtension() : void
- Unloads given extension
- executePositionedStringInsertion() : string
- Inserts as list of data into an existing list.
- removeDuplicatesForInsertion() : string
- Compares an existing list of items and a list of items to be inserted and returns a duplicate-free variant of that insertion list.
Properties
$packageManager
protected
static PackageManager
$packageManager
Methods
addFieldsToAllPalettesOfField()
Adds new fields to all palettes that is defined after an existing field.
public
static addFieldsToAllPalettesOfField(string $table, string $field, string $addFields[, string $insertionPosition = '' ]) : void
If the field does not have a following palette yet, it's created automatically and gets called "generatedFor-$field". FOR USE IN files in Configuration/TCA/Overrides/*.php Use in ext_tables.php FILES may break the frontend.
See unit tests for more examples and edge cases.
Example:
'aTable' => array( 'types' => array( 'aType' => array( 'showitem' => 'aField, --palette--;;aPalette', ), ), 'palettes' => array( 'aPalette' => array( 'showitem' => 'fieldB, fieldC', ), ), ),
Calling addFieldsToAllPalettesOfField('aTable', 'aField', 'newA', 'before: fieldC') results in:
'aTable' => array( 'types' => array( 'aType' => array( 'showitem' => 'aField, --palette--;;aPalette', ), ), 'palettes' => array( 'aPalette' => array( 'showitem' => 'fieldB, newA, fieldC', ), ), ),
Parameters
- $table : string
-
Name of the table
- $field : string
-
Name of the field that has the palette to be extended
- $addFields : string
-
Comma-separated list of fields to be added to the palette
- $insertionPosition : string = ''
-
Insert fields before (default) or after one
addFieldsToPalette()
Adds new fields to a palette.
public
static addFieldsToPalette(string $table, string $palette, string $addFields[, string $insertionPosition = '' ]) : void
If the palette does not exist yet, it's created automatically. FOR USE IN files in Configuration/TCA/Overrides/*.php Use in ext_tables.php FILES may break the frontend.
Parameters
- $table : string
-
Name of the table
- $palette : string
-
Name of the palette to be extended
- $addFields : string
-
Comma-separated list of fields to be added to the palette
- $insertionPosition : string = ''
-
Insert fields before (default) or after one
addFieldsToUserSettings()
Adds a list of new fields to the TYPO3 USER SETTINGS configuration "showitem" list, the array with the new fields itself needs to be added additionally to show up in the user setup, like $GLOBALS['TYPO3_USER_SETTINGS']['columns'] += $tempColumns
public
static addFieldsToUserSettings(string $addFields[, string $insertionPosition = '' ]) : void
Parameters
- $addFields : string
-
List of fields to be added to the user settings
- $insertionPosition : string = ''
-
Insert fields before (default) or after one
addPiFlexFormValue()
Adds an entry to the "ds" array of the tt_content field "pi_flexform".
public
static addPiFlexFormValue(string $piKeyToMatch, string $value[, string $CTypeToMatch = 'list' ]) : void
This is used by plugins to add a flexform XML reference / content for use when they are selected as plugin or content element. FOR USE IN files in Configuration/TCA/Overrides/*.php Use in ext_tables.php FILES may break the frontend.
Parameters
- $piKeyToMatch : string
-
Plugin key as used in the list_type field. Use the asterisk * to match all list_type values.
- $value : string
-
Either a reference to a flex-form XML file (eg. "FILE:EXT:newloginbox/flexform_ds.xml") or the XML directly.
- $CTypeToMatch : string = 'list'
-
Value of tt_content.CType (Content Type) to match. The default is "list" which corresponds to the "Insert Plugin" content element. Use the asterisk * to match all CType values.
Tags
addPlugin()
This is a helper method to add a new "frontend plugin". It therefore takes the $itemArray (label, value[,icon]) and adds to the items-array of $GLOBALS['TCA']['tt_content']['columns']['CType'|. So basically, this method adds a new "select item" to the tt_content record type column ("CType").
public
static addPlugin(array<string|int, mixed>|SelectItem $itemArray) : void
Additionally, this registers a given icon for the new record type and adds the plugin to the "plugin" group, in case no group is manually specified in the items array. If the value (array pos. 1) is already found in that items-array, the entry is substituted, otherwise the input array is added to the bottom.
Finally a basic "showitem" configuration is added for the plugin. However, this should be adjusted by either manually defining $GLOBALS['TCA']['tt_content']['types']['my_plugin'|['showitem'] or by calling further helper methods, such as ExtensionManagementUtility::addToAllTCAtypes().
FOR USE IN files in Configuration/TCA/Overrides/*.php Use in ext_tables.php FILES may break the frontend.
Parameters
- $itemArray : array<string|int, mixed>|SelectItem
-
Numerical or assoc array: [0 or 'label'] => Plugin label, [1 or 'value'] => Plugin identifier / plugin key, ideally prefixed with an extension-specific name (e.g. "events2_list"), [2 or 'icon'] => Icon identifier or path to plugin icon, [3 or 'group'] => an optional "group" ID, falls back to "plugins"
addRecordType()
Convenience method so you don't have to deal with strings and arrays and $GLOBALS[TCA] directly that much.
public
static addRecordType(array<string|int, mixed>|SelectItem $item, string $showItemList[, array<string|int, mixed> $additionalTypeInformation = [] ][, string $position = '' ][, string $table = 'tt_content' ]) : void
Adds a new entry to an existing TCA DB table that has a type field configured (via $TCA[$table][ctrl][type]) such as "tt_content" or "pages" tables.
Takes the $item (label, value[, icon] etc.) and adds the item to the items-array of $TCA[$table] of the "type" field. The position in the list can be chosen via the $position argument.
In addition, a type-icon gets registered, and, based on the $item[value], the record type is also added to $TCA[$table]['types'][$newType], where $showItemList is added as 'showitem' key, as well as $additionalTypeInformation such as 'columnsOverride' or 'creationOptions'.
In addition, the $showItemList will receive a 'extended' tab at the very end, so other extensions that add additional fields, will receive this at the extended tab automatically.
Can be used in favor of addPlugin() and addTcaSelectItem().
FOR USE IN files in Configuration/TCA/Overrides/*.php Use in ext_tables.php FILES may break the frontend.
Parameters
- $item : array<string|int, mixed>|SelectItem
-
The item to add to the select field
- $showItemList : string
-
A string containing all fields to be used / displayed in this type
- $additionalTypeInformation : array<string|int, mixed> = []
-
Additional type information to be added to the type in $TCA[$table]['types']
- $position : string = ''
-
The position in the list where the new item should be added, something like "after:textpic"
- $table : string = 'tt_content'
-
The table name, defaults to 'tt_content'
addService()
Adds a service to the global services array
public
static addService(string $extKey, string $serviceType, string $serviceKey, array<string|int, mixed> $info) : void
Parameters
- $extKey : string
-
Extension key
- $serviceType : string
-
Service type, must not be prefixed "tx_" or "Tx_"
- $serviceKey : string
-
Service key, must be prefixed "tx_", "Tx_" or "user_"
- $info : array<string|int, mixed>
-
Service description array
addStaticFile()
Call this method to add an entry in the static template list found in sys_templates FOR USE IN Configuration/TCA/Overrides/sys_template.php Use in ext_tables.php may break the frontend.
public
static addStaticFile(string $extKey, string $path, string $title) : void
Parameters
- $extKey : string
-
Is of course the extension key
- $path : string
-
Is the path where the template files "constants.typoscript", "setup.typoscript", and "include_static_file.txt" are found (relative to extPath, eg. "Configuration/TypoScript/Static/"). The file "include_static_file.txt", allows including other static templates defined in files, from your static template, and thus corresponds to the field 'include_static_file' in the sys_template table. The syntax for this is a comma separated list of static templates to include, example: EXT:fluid_styled_content/Configuration/TypoScript/,EXT:other_extension/Configuration/TypoScript/
- $title : string
-
Is the title in the selector box.
Tags
addTCAcolumns()
Adding fields to an existing table definition in $GLOBALS['TCA'] Adds an array with $GLOBALS['TCA'] column-configuration to the $GLOBALS['TCA']-entry for that table.
public
static addTCAcolumns(string $table, array<string|int, mixed> $columnArray) : void
This function adds the configuration needed for rendering of the field in TCEFORMS - but it does NOT add the field names to the types lists! So to have the fields displayed you must also call fx. addToAllTCAtypes or manually add the fields to the types list. FOR USE IN files in Configuration/TCA/Overrides/*.php . Use in ext_tables.php FILES may break the frontend.
Parameters
- $table : string
-
The table name of a table already present in $GLOBALS['TCA'] with a columns section
- $columnArray : array<string|int, mixed>
-
The array with the additional columns (typical some fields an extension wants to add)
addTcaSelectItem()
Add an item to a select field item list.
public
static addTcaSelectItem(string $table, string $field, array<string|int, mixed>|SelectItem $item[, string $relativeToField = '' ][, string $relativePosition = '' ]) : void
Warning: Do not use this method for radio or check types, especially not with $relativeToField and $relativePosition parameters. This would shift existing database data 'off by one'. FOR USE IN files in Configuration/TCA/Overrides/*.php Use in ext_tables.php FILES may break the frontend.
As an example, this can be used to add an item to tt_content CType select drop-down after the existing 'mailform' field with these parameters:
- $table = 'tt_content'
- $field = 'CType'
- $item = array( 'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:CType.I.10', 'login', 'i/imagename.gif', ),
- $relativeToField = mailform
- $relativePosition = after
$item has an optional fourth parameter for the groupId (string), to attach the new item to. The groupname is defined when a group is added with addTcaSelectItemGroup
Parameters
- $table : string
-
Name of TCA table
- $field : string
-
Name of TCA field
- $item : array<string|int, mixed>|SelectItem
-
New item to add
- $relativeToField : string = ''
-
Add item relative to existing field
- $relativePosition : string = ''
-
Valid keywords: 'before', 'after'
Tags
addTcaSelectItemGroup()
Adds an item group to a TCA select field, allows to add a group so addTcaSelectItem() can add a groupId with a label and its position within other groups.
public
static addTcaSelectItemGroup(string $table, string $field, string $groupId, string $groupLabel[, string|null $position = 'bottom' ]) : void
Parameters
- $table : string
-
the table name in TCA - e.g. tt_content
- $field : string
-
the field name in TCA - e.g. CType
- $groupId : string
-
the unique identifier for a group, where all items from addTcaSelectItem() with a group ID are connected
- $groupLabel : string
-
the label e.g. LLL:EXT:my_extension/Resources/Private/Language/locallang_tca.xlf:group.mygroupId
- $position : string|null = 'bottom'
-
e.g. "before:special", "after:default" (where the part after the colon is an existing groupId) or "top" or "bottom"
addToAllTCAtypes()
Makes fields visible in the TCEforms, adding them to the end of (all) "types"-configurations
public
static addToAllTCAtypes(string $table, string $newFieldsString[, string $typeList = '' ][, string $position = '' ]) : void
Adds a string $string (comma separated list of field names) to all ["types"][xxx]["showitem"] entries for table $table (unless limited by $typeList) This is needed to have new fields shown automatically in the TCEFORMS of a record from $table. Typically this function is called after having added new columns (database fields) with the addTCAcolumns function FOR USE IN files in Configuration/TCA/Overrides/*.php Use in ext_tables.php FILES may break the frontend.
Parameters
- $table : string
-
Table name
- $newFieldsString : string
-
Field list to add.
- $typeList : string = ''
-
Comma-separated list of specific types to add the field list to. (If empty, all type entries are affected)
- $position : string = ''
-
Insert fields before (default) or after one, or replace a field
addToInsertRecords()
Adds the $table tablename to the list of tables allowed to be includes by content element type "Insert records" By using $content_table and $content_field you can also use the function for other tables.
public
static addToInsertRecords(string $table[, string $content_table = 'tt_content' ][, string $content_field = 'records' ]) : void
FOR USE IN files in Configuration/TCA/Overrides/*.php Use in ext_tables.php FILES may break the frontend.
Parameters
- $table : string
-
Table name to allow for "insert record
- $content_table : string = 'tt_content'
-
Table name TO WHICH the $table name is applied. See $content_field as well.
- $content_field : string = 'records'
-
Field name in the database $content_table in which $table is allowed to be added as a reference ("Insert Record")
addTypoScript()
Adds $content to the default TypoScript code for either setup or constants as set in $GLOBALS['TYPO3_CONF_VARS'][FE]['defaultTypoScript_*'] (Basically this function can do the same as addTypoScriptSetup and addTypoScriptConstants - just with a little more hazzle, but also with some more options!) FOR USE IN ext_localconf.php FILES Note: As of TYPO3 CMS 6.2, static template #43 (content: default) was replaced with "defaultContentRendering" which makes it possible that a first extension like fluid_styled_content registers a "contentRendering" template (= a template that defines default content rendering TypoScript) by adding itself to $TYPO3_CONF_VARS[FE][contentRenderingTemplates][] = 'myext/Configuration/TypoScript'.
public
static addTypoScript(string $key, string $type, string $content[, int|string $afterStaticUid = 0 ][, bool $includeInSiteSets = true ]) : void
An extension calling addTypoScript('myext', 'setup', $typoScript, 'defaultContentRendering') will add its TypoScript directly after; For now, "43" and "defaultContentRendering" can be used, but "defaultContentRendering" is more descriptive and should be used in the future.
Parameters
- $key : string
-
Is the extension key (informative only).
- $type : string
-
Is either "setup" or "constants" and obviously determines which kind of TypoScript code we are adding.
- $content : string
-
Is the TS content, will be prefixed with a [GLOBAL] line and a comment-header.
- $afterStaticUid : int|string = 0
-
string pointing to the "key" of a static_file template ([reduced extension_key]/[local path]). The points is that the TypoScript you add is included only IF that static template is included (and in that case, right after). So effectively the TypoScript you set can specifically overrule settings from those static templates.
- $includeInSiteSets : bool = true
Tags
addTypoScriptConstants()
Adds $content to the default TypoScript constants code as set in $GLOBALS['TYPO3_CONF_VARS'][FE]['defaultTypoScript_constants'] NOT prefixed with a [GLOBAL] line, other calls MUST properly close their conditions! FOR USE IN ext_localconf.php FILES
public
static addTypoScriptConstants(string $content[, bool $includeInSiteSets = true ]) : void
Parameters
- $content : string
-
TypoScript Constants string
- $includeInSiteSets : bool = true
addTypoScriptSetup()
Adds $content to the default TypoScript setup code as set in $GLOBALS['TYPO3_CONF_VARS'][FE]['defaultTypoScript_setup'].
public
static addTypoScriptSetup(string $content[, bool $includeInSiteSets = true ]) : void
NOT prefixed with a [GLOBAL] line, other calls MUST properly close their conditions! FOR USE IN ext_localconf.php FILES
Parameters
- $content : string
-
TypoScript Setup string
- $includeInSiteSets : bool = true
deactivateService()
Deactivate a service
public
static deactivateService(string $serviceType, string $serviceKey) : void
Parameters
- $serviceType : string
-
Service type
- $serviceKey : string
-
Service key
extPath()
Returns the absolute path to the extension with extension key $key.
public
static extPath(string $key[, string $script = '' ]) : string
Parameters
- $key : string
-
Extension key
- $script : string = ''
-
$script is appended to the output if set.
Tags
Return values
stringfindService()
Find the available service with highest priority
public
static findService(string $serviceType[, string $serviceSubType = '' ][, array<string|int, mixed> $excludeServiceKeys = [] ]) : array<string|int, mixed>|false
Parameters
- $serviceType : string
-
Service type
- $serviceSubType : string = ''
-
Service sub type
- $excludeServiceKeys : array<string|int, mixed> = []
-
Service keys that should be excluded in the search for a service.
Return values
array<string|int, mixed>|false —Service info array if a service was found, FALSE otherwise
findServiceByKey()
Find a specific service identified by its key Note that this completely bypasses the notions of priority and quality
public
static findServiceByKey(string $serviceKey) : array<string|int, mixed>
Parameters
- $serviceKey : string
-
Service key
Tags
Return values
array<string|int, mixed> —Service info array if a service was found
getCN()
Returns the correct class name prefix for the extension key $key
public
static getCN(string $key) : string
Parameters
- $key : string
-
Extension key
Return values
stringgetExtensionVersion()
Retrieves the version of an installed extension.
public
static getExtensionVersion(string $key) : string
If the extension is not installed, this function returns an empty string.
Parameters
- $key : string
-
The key of the extension to look up; must not be empty.
Tags
Return values
string —The extension version as a string in the format "x.y.z",
getLoadedExtensionListArray()
Gets an array of loaded extension keys
public
static getLoadedExtensionListArray() : array<string|int, mixed>
Return values
array<string|int, mixed>isLoaded()
Returns TRUE if the extension with extension key $key is loaded.
public
static isLoaded(string $key) : bool
Parameters
- $key : string
Return values
boolisServiceAvailable()
Check if a given service is available, based on the executable files it depends on
public
static isServiceAvailable(string $serviceType, string $serviceKey, array<string|int, mixed> $serviceDetails) : bool
Parameters
- $serviceType : string
-
Type of service
- $serviceKey : string
-
Specific key of the service
- $serviceDetails : array<string|int, mixed>
-
Information about the service
Return values
bool —Service availability
loadExtension()
Loads given extension
public
static loadExtension(string $extensionKey) : void
Parameters
- $extensionKey : string
-
Extension key to load
Tags
registerPageTSConfigFile()
Call this method to add an entry in the page TSconfig list found in pages FOR USE in Configuration/TCA/Overrides/pages.php
public
static registerPageTSConfigFile(string $extKey, string $filePath, string $title) : void
Parameters
- $extKey : string
-
The extension key
- $filePath : string
-
The path where the TSconfig file is located
- $title : string
-
The title in the selector box
Tags
resolvePackagePath()
Temporary helper method to resolve paths with the PackageManager.
public
static resolvePackagePath(string $path) : string
The PackageManager is statically injected to this class already. This method will be removed without substitution in TYPO3 12 once a proper resource API is introduced.
Parameters
- $path : string
This method is only allowed to be called from GeneralUtility::getFileAbsFileName()! DONT'T introduce other usages!
Tags
Return values
stringsetPackageManager()
Sets the package manager for all that backwards compatibility stuff, so it doesn't have to be fetched through the bootstrap.
public
static setPackageManager(PackageManager $packageManager) : void
Parameters
- $packageManager : PackageManager
unloadExtension()
Unloads given extension
public
static unloadExtension(string $extensionKey) : void
Parameters
- $extensionKey : string
Tags
executePositionedStringInsertion()
Inserts as list of data into an existing list.
protected
static executePositionedStringInsertion(string $list, string $insertionList[, string $insertionPosition = '' ]) : string
The insertion position can be defined accordant before of after existing list items.
Example:
- list: 'field_a, field_b, field_c'
- insertionList: 'field_d, field_e'
- insertionPosition: 'after:field_b' -> 'field_a, field_b, field_d, field_e, field_c'
$insertPosition may contain ; and - characters: after:--palette--;;title
Parameters
- $list : string
-
The list of items to be extended
- $insertionList : string
-
The list of items to inserted
- $insertionPosition : string = ''
-
Insert fields before (default) or after one
Return values
string —The extended list
removeDuplicatesForInsertion()
Compares an existing list of items and a list of items to be inserted and returns a duplicate-free variant of that insertion list.
protected
static removeDuplicatesForInsertion(string $insertionList[, string $list = '' ]) : string
Example:
- list: 'field_a, field_b, field_c'
- insertion: 'field_b, field_d, field_c' -> new insertion: 'field_d'
Duplicate values in $insertionList are removed.
Parameters
- $insertionList : string
-
The comma-separated list of items to inserted
- $list : string = ''
-
The comma-separated list of items to be extended
Return values
string —Duplicate-free list of items to be inserted