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

Sluggable handlers (only available in annotations) #2841

Open
w-ap-admin opened this issue Jul 10, 2024 · 6 comments
Open

Sluggable handlers (only available in annotations) #2841

w-ap-admin opened this issue Jul 10, 2024 · 6 comments

Comments

@w-ap-admin
Copy link

w-ap-admin commented Jul 10, 2024

Hello,

I using doctrine-extension and I wodering why the argument handlers inside @Gedmo\Slug is available in annotations and not in attributes ?
It is a technical constraint or could I help with an PR ?

Thank you for anwser.

Have a nice day :-)

@w-ap-admin w-ap-admin changed the title Sluggable handlers (only available in annotations" Sluggable handlers (only available in annotations) Jul 10, 2024
@mbabker
Copy link
Contributor

mbabker commented Jul 10, 2024

When PHP 8.0 released, you couldn't instantiate objects in attributes, so this syntax wasn't valid:

#[Gedmo\Slug(handlers: [new Gedmo\SlugHandler()])]

As a side effect, projects providing annotations that had nested annotations needed to adjust how those nested objects were processed. Usually, that meant promoting those nested objects to the top level, such as:

#[Gedmo\Slug]
#[Gedmo\SlugHandler]

The Doctrine ORM has similar examples of this (compare the @Index annotation with the #[Index] attribute and you'll see a similar change).

One of the features of PHP 8.1 (see https://stitcher.io/blog/php-81-new-in-initializers for more on that) removed that limitation. So, technically, the annotations syntax could be supported in the attributes mapping driver for PHP 8.1 and later, but at this point I personally don't trying to support both options in the attribute driver (both the original implementation and bringing back the annotation-related nested structure) is worth the effort.

@nzhiti
Copy link

nzhiti commented Jul 10, 2024

#[Gedmo\Slug] #[Gedmo\SlugHandler]

Can slug handler being chained in order to have multiple RelativeSlugHandler ?

@mbabker
Copy link
Contributor

mbabker commented Jul 10, 2024

Yes, you can configure multiple slug handlers, see this test fixture as an example with both annotations and attributes.

If your question is specifically whether you can have multiple RelativeSlugHandler's with different configurations for one property, I truthfully don't know as I've not personally used that feature.

@nzhiti
Copy link

nzhiti commented Jul 10, 2024

Yes, you can configure multiple slug handlers, see this test fixture as an example with both annotations and attributes.

If your question is specifically whether you can have multiple RelativeSlugHandler's with different configurations for one property, I truthfully don't know as I've not personally used that feature.

That's exactly what I want, I'd like the slug being build based on relations fields. And only the last relativeSlugHandler was user to build the slug.

@mbabker
Copy link
Contributor

mbabker commented Jul 10, 2024

OK, well that's a separate feature request from this item (which is mainly about the config difference between annotations and attributes). On a quick glance, it seems like the mapping driver keys the handlers array by class name, so that would definitely preclude multiple slug handlers of the same type being used on one property. I was going to say maybe there's a way to work around it with a custom chain implementation of the SlugHandlerInterface, but with the way all the existing handlers fetch their data, the idea that I had just won't work for your use case without basically re-implementing the handlers you need.

@nzhiti
Copy link

nzhiti commented Jul 10, 2024

OK, well that's a separate feature request from this item (which is mainly about the config difference between annotations and attributes). On a quick glance, it seems like the mapping driver keys the handlers array by class name, so that would definitely preclude multiple slug handlers of the same type being used on one property. I was going to say maybe there's a way to work around it with a custom chain implementation of the SlugHandlerInterface, but with the way all the existing handlers fetch their data, the idea that I had just won't work for your use case without basically re-implementing the handlers you need.

Thank you ill dig into it and keep this post updated

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

No branches or pull requests

3 participants