ext_localconf.php

– optional

ext_localconf.php is always included in global scope of the script, in the frontend, backend and CLI context.

It should contain additional configuration of $GLOBALS['TYPO3_CONF_VARS'].

This file contains hook definitions and plugin configuration. It must not contain a PHP encoding declaration.

All ext_localconf.php files of loaded extensions are included right after the files typo3conf/LocalConfiguration.php and typo3conf/AdditionalConfiguration.php during TYPO3 bootstrap.

Pay attention to the rules for the contents of these files. For more details, see the section below.

Should not be used for

While you can put functions and classes into ext_localconf.php, it considered bad practice because such classes and functions would always be loaded. Move such functionality to services or utility classes instead.

Registering hooks, XCLASSes or any simple array assignments to $GLOBALS['TYPO3_CONF_VARS'] options will not work for the following:

  • class loader
  • package manager
  • cache manager
  • configuration manager
  • log manager (= Logging Framework)
  • time zone
  • memory limit
  • locales
  • stream wrapper
  • error handler

This would not work because the extension files ext_localconf.php are included (loadTypo3LoadedExtAndExtLocalconf) after the creation of the mentioned objects in the Bootstrap class.

In most cases, these assignments should be placed in typo3conf/AdditionalConfiguration.php.

Example:

Register an exception handler:

typo3conf/AdditionalConfiguration.php
$GLOBALS['TYPO3_CONF_VARS']['SYS']['debugExceptionHandler'] =
    \Vendor\Ext\Error\PostExceptionsOnTwitter::class;

Deprecated since version 11.5: Icons should be registered in Icons.php.

See also: IconRegistry

Should be used for

These are the typical functions that extension authors should place within file:ext_localconf.php

  • Registering hooks, XCLASSes or any simple array assignments to $GLOBALS['TYPO3_CONF_VARS'] options
  • Registering additional Request Handlers within the Bootstrap
  • Adding any PageTSconfig
  • Adding default TypoScript via \TYPO3\CMS\Core\Utility\ExtensionManagementUtility APIs
  • Registering Scheduler Tasks
  • Adding reports to the reports module
  • Registering Services via the Service API

Examples

Put a file called ext_localconf.php in the main directory of your Extension. It does not need to be registered anywhere but will be loaded automatically as soon as the extension is installed. The skeleton of the ext_localconf.php looks like this:

EXT:site_package/ext_localconf.php
<?php
// all use statements must come first
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;

// Prevent Script from being called directly
defined('TYPO3') or die();

// encapsulate all locally defined variables
(function () {
    // Add your code here
})();

Adding default PageTSconfig

Default PageTSconfig can be added inside ext_localconf.php, see Setting the Page TSconfig globally:

EXT:site_package/ext_localconf.php
//use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;

ExtensionManagementUtility::addPageTSConfig();

PageTSconfig available via static files can be added inside Configuration/TCA/Overrides/pages.php, see Static Page TSconfig:

EXT:site_package/Configuration/TCA/Overrides/pages.php
ExtensionManagementUtility::registerPageTSConfigFile();

Adding default UserTSconfig

As for default PageTSconfig, UserTSconfig can be added inside ext_localconf.php, see: Setting default user TSconfig:

EXT:site_package/ext_localconf.php
//use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;

ExtensionManagementUtility::addUserTSConfig();