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
array
$attributes
An array of attributes.
$context
A
\Contao\DataContainer
or\Contao\Module
object. It can benull
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;
}
}