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 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 of the KnpMenuBundle. This can be used to alter the back end menu to your needs. An example of this can also 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 available in Contao 4.7 and later.

This event is dispatched after Contao generated 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 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 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

FilterPageTypeEvent

This feature is available in Contao 4.10 and later.

This event event is triggered when the available page types are collected in the PageTypeOptionsListener for the type select of tl_page. The event allows you to add or remove options.

Name\Contao\CoreBundle\Event\FilterPageTypeEvent::class
ConstantN/A
Event\Contao\CoreBundle\Event\FilterPageTypeEvent

Example

contao.sitemap

This feature is available in Contao 4.11 and later.

This event is triggered in Contao’s SitemapController when the sitemap is built. The event allows you to modify the XML DOM of the sitemap. The event also stores for which website roots this sitemap was created.

Namecontao.sitemap
Constant\Contao\CoreBundle\Event\ContaoCoreEvents::SITEMAP
Event\Contao\CoreBundle\Event\SitemapEvent

Example

SendNewsletterEvent

This feature is available in Contao 4.13 and later.

This event is triggered for each newsletter mail and allows you to customize the newsletter text and HTML content, prevent the submission or perform other related actions to the newsletter (e.g. logging).

The event is triggered when sending a newsletter preview as well as when sending a newsletter to real recipients.

Name\Contao\NewsletterBundle\Event\SendNewsletterEvent::class
ConstantN/A
Event\Contao\NewsletterBundle\Event\SendNewsletterEvent

Example

FetchArticlesForFeedEvent

This feature is available in Contao 5.0 and later.

This event is dispatched when a news feed is created and is used to collect the news articles before adding them to the feed. The event holds references to the feed, the page and the request and allows news articles to be added to it. This event is also used by the news bundle itself, so if you want to alter the collection of news articles (before they are added to the feed) make sure that your event listener has a lower priority.

This event also allows you to alter the feed directly.

Name\Contao\NewsBundle\Event\FetchArticlesForFeedEvent::class
ConstantN/A
Event\Contao\NewsBundle\Event\FetchArticlesForFeedEvent
Example

TransformArticleForFeedEvent

This feature is available in Contao 5.0 and later.

This event is dispatched when a news article is transformed to a news feed item node. The event holds a reference to the news archive, feed, page, request and the base URL. The news bundle uses this event to create a feed item based on a news record and sets this item in the event. You can use this event to further alter the feed item (if your event listener has a lower priority).

Name\Contao\NewsBundle\Event\TransformArticleForFeedEvent::class
ConstantN/A
Event\Contao\NewsBundle\Event\TransformArticleForFeedEvent
Example