Events

Contao implements a variety of events using the Symfony Event Dispatcher. These events are often used internally but also provide you with ways to customise specific flows of the application, in addition to Hooks.

contao.backend_menu_build

This feature is only available in Contao 4.5 and later.

This event is dispatched, when the Contao back end menu is built. The event contains references to the menu factory as well as the menu tree object. This can be used to alter the back end menu to your needs. An example of this can be found in the Back End Routes guide.

Namecontao.backend_menu_build
Constant\Contao\CoreBundle\Event\ContaoCoreEvents::BACKEND_MENU_BUILD
Event\Contao\CoreBundle\Event\MenuEvent

Example

This feature is only available in Contao 4.7 and later.

This event is dispatched after Contao generateed all its necessary symlinks (e.g. from web/files/ to all the public folders in files/). The event object returns a list of custom symlinks to be built and offers the possibility to add your own custom symlink to the list.

Namecontao.generate_symlinks
Constant\Contao\CoreBundle\Event\ContaoCoreEvents::GENERATE_SYMLINKS
Event\Contao\CoreBundle\Event\GenerateSymlinksEvent

Example

contao.image_sizes_all

This event is dispatched when all the available image sizes for selection in the back end are collected. The event allows to return all the currently set image sizes and lets you define a new set of image sizes. It also returns back end user, for which these image sizes are collected. This allows you to customize the list of offered image sizes.

Namecontao.image_sizes_all
Constant\Contao\CoreBundle\Event\ContaoCoreEvents::IMAGE_SIZES_ALL
Event\Contao\CoreBundle\Event\ImageSizesEvent

Example

contao.image_sizes_user

This event is similar to contao.image_sizes_all, except that the list of image sizes is already filtered according to the current back end user.

Namecontao.image_sizes_user
Constant\Contao\CoreBundle\Event\ContaoCoreEvents::IMAGE_SIZES_USER
Event\Contao\CoreBundle\Event\ImageSizesEvent

Example

contao.preview_url_create

This event is triggered when a preview URL for the front end within the back end is created. The event provides the set ID, key and query and allows you to set or override the query parameter.

Namecontao.preview_url_create
Constant\Contao\CoreBundle\Event\ContaoCoreEvents::PREVIEW_URL_CREATE
Event\Contao\CoreBundle\Event\PreviewUrlCreateEvent

Example

contao.preview_url_convert

When a request to the preview controller is made, this event can be used to redirect the user to a specific front end URL within the preview mode. Otherwise a redirect to the root page is made. Contao uses this to translate a request to the the preview controller into a front end request URL.

Namecontao.preview_url_convert
Constant\Contao\CoreBundle\Event\ContaoCoreEvents::PREVIEW_URL_CONVERT
Event\Contao\CoreBundle\Event\PreviewUrlConvertEvent

Example

contao.robots_txt

This feature is only available in Contao 4.9 and later.

This event is triggered when the /robots.txt route is called. The event allows you to retrieve the webignition\RobotsTxt\File\File object of the dynamically generated robots.txt, which allows you to add your own custom records programatically. See the README of webignition/robots-txt-file for more details.

Namecontao.robots_txt
Constant\Contao\CoreBundle\Event\ContaoCoreEvents::ROBOTS_TXT
Event\Contao\CoreBundle\Event\RobotsTxtEvent

Example

contao.slug_valid_characters

This feature is only available in Contao 4.5 and later.

This event event is triggered when the valid slug characters options in the back end are generated. The event allows you to set custom options.

Namecontao.slug_valid_characters
Constant\Contao\CoreBundle\Event\ContaoCoreEvents::SLUG_VALID_CHARACTERS
Event\Contao\CoreBundle\Event\SlugValidCharactersEvent

Example