Skip to content

Feature request: a displayIf(callable) for Fields. #7543

Open

Description

@armellin

It would be nice to have a displayIf(callable) method for Fields, similar to the one used for Actions.

It would be useful, in detail, edit, and new, to set a criterion for displaying the field according to the properties of the Entity, e.g.:

yield TextField::new('reason')->displayIf(fn (?Order $entity) => $entity?->isCancelled());

The implementation could be:

// src/Field/FieldTrait.php

public function displayIf(callable $callable): self
{
    $this->dto->setDisplayCallable($callable);

    return $this;
}
// src/Dto/FieldDto.php

private $displayCallable;

public function setDisplayCallable(callable $displayCallable): void
{
    $this->displayCallable = $displayCallable;
}

public function shouldBeDisplayedFor(EntityDto $entityDto): bool
{
    return null === $this->displayCallable || \call_user_func($this->displayCallable, $entityDto->getInstance());
}
// src/Factory/FieldFactory.php

public function processFields(EntityDto $entityDto, FieldCollection $fields, string $currentPage): void

    ..............

    if (Crud::PAGE_INDEX !== $currentPage && false === $fieldDto->shouldBeDisplayedFor($entityDto)) {
        $fields->unset($fieldDto);
        continue;
    }

    ..............

}

Activity

  1. added this to the 5.x milestone on Apr 16, 2026
  2. github-actions commented on Jul 16, 2026

    @github-actions

    This issue has been inactive for 3 months. It will be closed in 5 days
    unless there is new activity.

    Check if this is still relevant (maybe it was already fixed by some PR)
    and leave a comment or update the issue with any new information.

  3. armellin commented on Jul 16, 2026

    @armellin
    Author

    Any comment on this idea?

  4. github-actions commented on Oct 16, 2026

    @github-actions

    This issue has been inactive for 3 months. It will be closed in 5 days
    unless there is new activity.

    Check if this is still relevant (maybe it was already fixed by some PR)
    and leave a comment or update the issue with any new information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions