The getAttributesFromDca hook is triggered when attributes of a widget are extracted from a Data Container array. It passes the attributes and the DCA object as arguments and expects the (modified) widget attributes as return value. Note that the DCA object can be optional (null).


  1. array $attributes

    An array of attributes.

  2. $context

    A \Contao\DataContainer or \Contao\Module object. It can be null if no object was passed to the \Contao\Widget::getAttributesFromDca method.

Return Values

Return the attributes for the widget as an associative array.


// src/EventListener/GetAttributesFromDcaListener.php
namespace App\EventListener;

use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;

class GetAttributesFromDcaListener
    public function __invoke(array $attributes, $context = null): array
        // Modify $attributes here …

        return $attributes;