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

Support for BackedEnumFilter #6506

Closed
mremi opened this issue Aug 9, 2024 · 2 comments · Fixed by #6547
Closed

Support for BackedEnumFilter #6506

mremi opened this issue Aug 9, 2024 · 2 comments · Fixed by #6547

Comments

@mremi
Copy link
Contributor

mremi commented Aug 9, 2024

Description

Is a new Doctrine filter BackedEnumFilter could be interesting for filtering an entity using backed enum?

Example

Could be used in this way:

<?php

namespace App\Entity;

#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ApiResource(
    operations: [
        new Get(normalizationContext: ['groups' => 'user:item']),
        new GetCollection(normalizationContext: ['groups' => 'user:list']),
    ],
)]
#[ApiFilter(BackedEnumFilter::class, properties: ['status'])]
class User
{
    #[ORM\Column(enumType: UserStatus::class, options: ['default' => UserStatus::Active])]
    #[Groups(['user:list', 'user:item'])]
    private UserStatus $status = UserStatus::Active;
}

with an Enum like this:

<?php

enum UserStatus: string
{
    case Active = 'active';
    case Blocked = 'blocked';
}
@soyuka
Copy link
Member

soyuka commented Aug 9, 2024

Why not indeed!

mremi added a commit to mremi/api-platform-core that referenced this issue Aug 26, 2024
mremi added a commit to mremi/api-platform-core that referenced this issue Aug 26, 2024
mremi added a commit to mremi/api-platform-core that referenced this issue Aug 26, 2024
mremi added a commit to mremi/api-platform-core that referenced this issue Aug 26, 2024
mremi added a commit to mremi/api-platform-core that referenced this issue Aug 27, 2024
mremi added a commit to mremi/api-platform-core that referenced this issue Aug 27, 2024
mremi added a commit to mremi/api-platform-core that referenced this issue Aug 29, 2024
@soyuka soyuka closed this as completed in cd2dbd0 Aug 30, 2024
soyuka added a commit that referenced this issue Aug 30, 2024
…ed enum, resolves #6506 (#6547) (#6560)

Co-authored-by: Rémi Marseille <marseille.remi@gmail.com>
@rvanlaak
Copy link

Great feature! Makes me think, what about allowing to exclude certain enum values from the filtering? For example, based on a permission schema "provider" or some other of the more complex use-cases? Worth creating a ticket for that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants