compileFormFields
The compileFormFields hook is triggered when the fields of a form are compiled.
It passes the form fields, the ID of the form and the form object as arguments
and expects the modified form fields as return value.
Parameters
array
$fieldsAn array of
\Contao\FormFieldModelinstances.string
$formIdAlias of the current form with the prefix
auto_. Don’t confuse with$form->id.\Contao\Form
$formThe form (an instance of
\Contao\Form).
Return Values
An array of of \Contao\FormFieldModel instances.
Example
// src/EventListener/CompileFormFieldsListener.php
namespace App\EventListener;
use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;
use Contao\Form;
#[AsHook('compileFormFields')]
class CompileFormFieldsListener
{
public function __invoke(array $fields, string $formId, Form $form): array
{
// Modify $fields as needed
return $fields;
}
}