EasyCorp/EasyAdminBundle

Ability to add html attributes to crud pages

KDederichs opened this issue · 2 comments

Short description of what this feature will allow to do:
Add ability to add html attributes to crud pages.

Example of how to use this feature
Would be useful to add Stimulus directives to CRUD pages (data-controller)

    #[\Override] public function configureCrud(Crud $crud): Crud
    {
        $crud->setHtmlAttribute('data-controller', 'clipboard');
        return $crud;
    }

Hello,

This solution works for me in my CrudController ( with "easycorp/easyadmin-bundle": "^4.9"):

public function configureCrud(Crud $crud): Crud
{
    $crud->setFormOptions([
        'attr' => [
            'data-controller' => 'coupon' // = <form data-controller="coupon" ...>
        ]
    ]);
 }
 
public function configureFields(string $pageName): iterable
{
  yield TextField::new('code', 'Code')
      ->setFormTypeOptions([
          'attr' => [
              'data-coupon-target' => 'input'
          ]
      ])
      ->setHelp('<a data-action="coupon#generate" class="btn btn-primary" href="#">Generate random code</a>')
  ;
}

Sure I know that works on forms, but there's no form on index to attach the controller to.