getAttributesFromDca

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).

Parameters

  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.

Example

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

use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;

#[AsHook('getAttributesFromDca')]
class GetAttributesFromDcaListener
{
    public function __invoke(array $attributes, $context = null): array
    {
        // Modify $attributes here …

        return $attributes;
    }
}

References