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

EntityRoute does not support enum fields #17473

Open
asgraf opened this issue Dec 7, 2023 · 4 comments
Open

EntityRoute does not support enum fields #17473

asgraf opened this issue Dec 7, 2023 · 4 comments

Comments

@asgraf
Copy link

asgraf commented Dec 7, 2023

Description

I don't know is this ticket should be classified as bug or as feature request (kinda both)

Currently, EntityRoute simply does not work with \BackedEnum fields as expected.
For purpose of routing \StringBackedEnum values should be casted to strings and \IntBackedEnum values should be casted to ints
I currently already do this in my CustomEntityRoute class but i feel this should be part of the base CakePHP

CakePHP Version

5.x

PHP Version

No response

@asgraf asgraf added the defect label Dec 7, 2023
@dereuromark dereuromark added this to the 5.0.4 milestone Dec 7, 2023
@asgraf
Copy link
Author

asgraf commented Dec 7, 2023

Additionaly RouteBuilder could also get some Enum support.

Currently i need to make enum routes like this:

$builder->connect(
    '/create/{sharing_type}/ipv6',
    ['action' => 'add', 'ip_version' => IpVersion::IPv6->value],
    ['sharing_type' => implode('|', array_column(SharingType::cases(), 'value'))]
);
$builder->connect(
    '/create/{sharing_type}/',
    ['action' => 'add', 'ip_version' => IpVersion::IPv4->value],
    ['sharing_type' => implode('|', array_column(SharingType::cases(), 'value'))]
);

native support for enums in routing logic itself this could allow this example to trimmed down to:

$builder->connect(
    '/create/{sharing_type}/ipv6',
    ['action' => 'add', 'ip_version' => IpVersion::IPv6],
    ['sharing_type' => SharingType::cases()]
);
$builder->connect(
    '/create/{sharing_type}/',
    ['action' => 'add', 'ip_version' => IpVersion::IPv4],
    ['sharing_type' => SharingType::cases()]
);

@dereuromark dereuromark changed the title EntityRoute does not suport enum fields EntityRoute does not support enum fields Dec 9, 2023
@dereuromark
Copy link
Member

Do you want to make a PR for 5.next to add support for this?

@markstory markstory modified the milestones: 5.0.4, 5.1.0 Dec 9, 2023
@markstory
Copy link
Member

Bumping to 5.1 as we haven't implemented enum support into routes yet, so it isn't a defect. I do agree that it is a useful addition 😄

Copy link

github-actions bot commented Apr 8, 2024

This issue is stale because it has been open for 120 days with no activity. Remove the stale label or comment or this will be closed in 15 days

@github-actions github-actions bot added the stale label Apr 8, 2024
@dereuromark dereuromark added pinned and removed stale labels Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants