We will start with the simplest example Hello World
. Once we understood the
basics, we will create an “address” extension to manage a custom record.
Extensions consists of a folder and the single necessary file, which is
ext_emconf.php
. This configures the Extension Manager. Without this file,
the Extension Manager would not recognize the extension and would prevent
installation.
<?php
$EM_CONF['example_extension'] = [
'title' => 'Example extension',
'description' => 'Example for TYPO3 Extension Workshop.',
'category' => 'example',
'version' => '1.0.0',
'state' => 'stable',
'author' => 'Daniel Siepmann',
'author_email' => 'coding@daniel-siepmann.de',
'author_company' => 'Codappix',
'constraints' => [
'depends' => [
'php' => '7.2.0-7.2.999',
'typo3' => '8.7.0-9.5.999',
],
],
'autoload' => [
'psr-4' => [
'Workshop\\ExampleExtension\\' => 'Classes',
]
],
];
See Declaration file in TYPO3 Core API Reference.
Task
So let’s create a new folder and add the file within the folder.
In this example I’ll use example_extension
as folder name.
Once we have created the first extension, we need to install the extension. There are two ways for a local extension. Either placing the extension inside the installation, or via composer.
Task
Install the new extension.
Copy the extension to typo3conf/ext/
, and head over to Extension Manager to
activate the extension.
The following project setup is suggested:
.
├── composer.json
└── localPackages
└── example_extension
composer.json
:
{
"repositories": [
{
"type": "path",
"url": "localPackages/*"
},
{
"type": "composer",
"url": "https://composer.typo3.org/"
}
],
"name": "website/typo3-extension-workshop",
"description": "Example TYPO3 installation for workshop",
"license": "GPL-2.0-or-later",
"require": {
"helhum/typo3-console": "^5.5.5",
"helhum/typo3-secure-web": "^0.2.7",
"typo3-console/composer-auto-commands": "^0.2.0",
"typo3/cms-core": "^9.5.0",
"typo3/cms-about": "*",
"typo3/cms-belog": "*",
"typo3/cms-beuser": "*",
"typo3/cms-fluid-styled-content": "*",
"typo3/cms-info": "*",
"typo3/cms-info-pagetsconfig": "*",
"typo3/cms-rte-ckeditor": "*",
"typo3/cms-setup": "*",
"typo3/cms-t3editor": "*",
"typo3/cms-tstemplate": "*",
"workshop/example-extension": "@dev"
},
"require-dev": {
"typo3/cms-lowlevel": "*"
},
"extra": {
"typo3/cms": {
"app-dir": "app",
"root-dir": "app",
"web-dir": "public"
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
In this case, we also need a composer.json
inside our extension, to make the
extension an composer package and allow the installation:
composer.json
:
{
"name": "workshop/example-extension",
"description": "Example for TYPO3 Extension Workshop.",
"type": "typo3-cms-extension",
"license": "GPL-2.0-or-later",
"authors": [
{
"name": "Daniel Siepmann",
"email": "coding@daniel-siepmann.de"
}
],
"autoload": {
"psr-4": {
"Workshop\\ExampleExtension\\": "Classes"
}
},
"require": {
"php": ">=7.2.0",
"typo3/cms-core": "*"
}
}
Thanks due typo3-console/composer-auto-commands
our extension is activated already.
Using composer, TYPO3 does not do any special. The autoloading is provided by composer and can be configured as documented by composer.
If you are not using composer, you should provide autoloading information inside
ext_emconf.php
:
<?php
$EM_CONF['example_extension'] = [
'autoload' => [
'psr-4' => [
'Workshop\\ExampleExtension\\' => 'Classes',
]
],
];
There you can follow the composer autoloading configuration.
You can find the composer documentation about autoloading at https://getcomposer.org/doc/04-schema.md#autoload .