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. \Contao\DataContainer $dc

    The DataContainer 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\ServiceAnnotation\Hook;
use Contao\DataContainer;
use Terminal42\ServiceAnnotationBundle\ServiceAnnotationInterface;

class GetAttributesFromDcaListener implements ServiceAnnotationInterface
{
    /**
     * @Hook("getAttributesFromDca")
     */
    public function onGetAttributesFromDca(array $attributes, DataContainer $dc = null): array
    {
        // Modify $attributes here …

        return $attributes;
    }
}

References