Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add addDisplayOnPage in src/Field/FieldTrait.php #6318

Open
ceponcet opened this issue Jun 5, 2024 · 1 comment · May be fixed by #6319
Open

Add addDisplayOnPage in src/Field/FieldTrait.php #6318

ceponcet opened this issue Jun 5, 2024 · 1 comment · May be fixed by #6319
Labels
Milestone

Comments

@ceponcet
Copy link
Contributor

ceponcet commented Jun 5, 2024

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 added a commit to ceponcet/EasyAdminBundle that referenced this issue Jun 5, 2024
@ceponcet ceponcet linked a pull request Jun 5, 2024 that will close this issue
@Seb33300
Copy link
Contributor

Seb33300 commented Jun 8, 2024

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');
    }
}

@javiereguiluz javiereguiluz added this to the 4.x milestone Aug 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants