This bundle offers various utility functionality for the Contao CMS.

Installs: 85 077

Dependents: 86

Suggesters: 1

Security: 0

Stars: 7

Watchers: 6

Forks: 4

Open Issues: 5


3.0.0-beta 2023-10-29 21:55 UTC

This package is auto-updated.

Last update: 2023-11-14 14:55:10 UTC


example branch parameter Coverage Status

Hi, you're looking on a very new version of utils bundle, version 3! See CHANGELOG.md for more information! If you're looking for version 2, please check the v2 branch.

Utils Bundle is a collection of many small helper to solve repeating task. At the center there is a utils service allow access to all util function. In addition, there are DcaField helpers, the Entity finder command and some nice twig filters.


  • Utils-Service - A service allow access all bundles utils functions.
  • DcaField registration - An nice api to add typical dca fields to your dca fields without repeating yourself or annoying order restrictions.
    • AuthorField - Add an author field with automatic filling of the default value and optional frontend member support
  • Entity Finder - A command to search for any contao entities in your database.
  • Twig Filters


Just install it via composer or contao manager:

composer require heimrichhannot/contao-utils-bundle


Utils service

The Utils service is the core functionality of this bundle. It provides access to a lot of util functions help solving recurring tasks. It's build as one service from which you can access all utils services. The utils service is best used with dependency injection, but is also available from the service container as public service for usage in legacy code. You can check the API Documentation to see all available functions.

use HeimrichHannot\UtilsBundle\Util\Utils;

 * A class containing examples usage of utils services. Please don't expect it to be useful :)
class MyClass{
   /** @var Utils */
   protected $utils;
   public function __construct(Utils $utils) {
       $this->utils = $utils;
   public function someActions(): bool {
        $dcaFields = $this->utils->dca()->getDcaFields('tl_content');
        $this->utils->array()->removeValue('headline', $dcaFields);
        foreach ($dcaFields as $dcaField) {
            echo $this->utils->string()->camelCaseToDashed($dcaField);
        $rootPageModel = $this->utils->request()->getCurrentRootPageModel();
        echo $this->utils->anonymize()->anonymizeEmail($rootPageModel->adminEmail);
        $groupUsers = $this->utils->user()->findActiveUsersByGroup([1,2]);
        $this->utils->url()->addQueryStringParameterToUrl('user='.$groupUsers[0]->username, 'https://example.org');
        if ($this->utils->container()->isBackend()) {
            $where = $this->utils->database()->createWhereForSerializedBlob('dumbData', ['foo', 'bar']);
            $model = $this->utils->model()->findOneModelInstanceBy('tl_content', [$where->createAndWhere()], [$where->values]);
            echo '<div '.$this->utils->html()->generateAttributeString($model->getHtmlAttributes()).'></div>';

Dca Fields

The bundle provides some common dca fields that can be used in your dca files.

Author field

Add an author field to your dca. It will be initialized with the current backend user. On copy, it will be set to the current user.

# contao/dca/tl_example.php
use HeimrichHannot\UtilsBundle\Dca\AuthorField;


You can pass additional options to adjust the field:

# contao/dca/tl_example.php
use HeimrichHannot\UtilsBundle\Dca\AuthorField;

    ->setType(AuthorField::TYPE_MEMBER) // can be one of TYPE_USER (default) or TYPE_MEMBER. Use TYPE_MEMBER to set a frontend member instead of a backend user
    ->setFieldNamePrefix('example') // custom prefix for the field name
    ->setUseDefaultLabel(false) // set to false to disable the default label and set a custom label in your dca translations
    ->setExclude(false) // set the dca field exclude option
    ->setSearch(false) // set the dca field search option
    ->setFilter(false) // set the dca field filter option

Entity Finder

The entity finder is a command to search for any contao entities in your database.

Entity finder

Twig Filters

This bundle contains currently one twig filter:


Returns an anonymized email address. max.muster@example.org will be max.****@example.org

{{ user.email|anonymize_email }}


Backwards Compatibility Promise

We try our best to keep this bundle backwards compatible and follow the principle of semantic versioning.

Following aspects are not covered by BC promise:

  • Using Utils classes direct instead from Utils service. This is not officially supported and may break your application due internal changes.
  • Classes marked as @internal or @experimental