EasyAdminBundle icon indicating copy to clipboard operation
EasyAdminBundle copied to clipboard

Add addDisplayOnPage in src/Field/FieldTrait.php

Open ceponcet opened this issue 1 year ago • 1 comments

Short description of what this feature will allow to do: Add addDisplayOnPage(string $pageName) in src/Field/FieldTrait.php

Adding the addDisplayOnPage(string $pageName) method to the src/Field/FieldTrait.php trait allows adding a field to a "page" other than EDIT INDEX DETAIL NEW. These other pages can be, for example, CSV or WHATEVER.

Example of how to use this feature

#src/Controller/Admin/MyCrudController.php
[...]
public function configureFields(string $pageName): iterable
{
      yield TextField::new('field')
            ->addDisplayOnPage("CSV")
            ->hideOnIndex()->hideOnForm()->hideOnDetail();
}

# And in another method, We retrieve only fields of CSV PAGE
public function export(AdminContext $context): Response
{
     //
        $context->getCrud()->setPageName("CSV");
     //
}


ceponcet avatar Jun 05 '24 14:06 ceponcet

In order to be consistent with existing method names, I suggest to rename addDisplayOnPage(string $pageName) into onlyOn(string $pageName) + another hideOn(string $pageName)

A workaround for now should be:

public function configureFields(string $pageName): iterable
{
    if ('CSV' == $pageName) {
        yield TextField::new('field');
    }
}

Seb33300 avatar Jun 08 '24 06:06 Seb33300