Skip to content

Add "entity" property to FieldDto or "displayIf" method #6102

@zorn-v

Description

@zorn-v

It can be useful when you need check other fields in voter for example.
Imagine users crud and disabled field in user entity.
It is weird to allow disable yourself, so better to hide that field for yourself entity.
Currently I inject AdminContextProvider and get current entity via AdminContext, but it is not possible to do it for index where ajax boolean switches (so I just disabled them all on index).

Also maybe add some generic displayIf method for field with callback. Maybe with entity parameter (if adding property is not preferably)
Something like

Field::new('disabled')->displayIf(fn ($field, $entity) => $entity->getId() !== $this->getUser()->getId());

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions