Skip to content

Conversation

@eerison
Copy link
Contributor

@eerison eerison commented Oct 24, 2025

Replace slugify to symfony string

Closes #1713.
Related PR: #1718.

Changelog

### Added
- `FixPageUrlService` contains the logic from `$pageManager->fixUrl($page)`
- `FixPageUrlInterface` was added.
 
### Deprecated
- `SlugifyInterface` has been deprecated in favour of the`SluggerInterface` from `symfony/string`

@eerison eerison force-pushed the feature/1713-rework-replace-slugify-to-symfony-string branch 2 times, most recently from fa5bd18 to 1b2b50f Compare October 25, 2025 09:27
@eerison
Copy link
Contributor Author

eerison commented Oct 25, 2025

hey @VincentLanglet

do you know why doctrine.orm.entity_listener does not work 😄 ?

Edit: I used Entity/BasePage (it worked)

@eerison eerison force-pushed the feature/1713-rework-replace-slugify-to-symfony-string branch from 005f0e5 to 47641d2 Compare October 25, 2025 18:07
Copy link
Member

@VincentLanglet VincentLanglet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like there is to many changes in a single PR.

If the purpose is to replace suglify by symfony string, why not JUST:

  • changing SlugifyInterface into SlugifyInterface|SluggerInterface
  • Updating the code to work with both
  • Deprecating SlugifyInterface

?

Currently you are

  • Introducing a new interface
  • Introducing a new class
  • Allowing SlugifyInterface|FixPageUrlInterface in PageManager
  • Adding a deprecation
  • Introducing an Adapter
  • Introducing a Factory
  • Introducing a Listener
  • And removing a fixUrl call in the validator

Be aware that sonata-project repository have almost no maintainer, so the smaller are the change, the better it is

@eerison
Copy link
Contributor Author

eerison commented Oct 26, 2025

I feel like there is to many changes in a single PR.

If the purpose is to replace suglify by symfony string, why not JUST:

  • changing SlugifyInterface into SlugifyInterface|SluggerInterface
  • Updating the code to work with both
  • Deprecating SlugifyInterface

?

Currently you are

  • Introducing a new interface
  • Introducing a new class
  • Allowing SlugifyInterface|FixPageUrlInterface in PageManager
  • Adding a deprecation
  • Introducing an Adapter
  • Introducing a Factory
  • Introducing a Listener
  • And removing a fixUrl call in the validator

Be aware that sonata-project repository have almost no maintainer, so the smaller are the change, the better it is

Yeah I know it is a bit big , I was trying to avoid it.

SlugifyInterface|SluggerInterface

It was my first thought, but I wanted to move this logical for a separated layer. But extracting the logical lead for a PR with too many things.

I was trying to avoid change the arguments, and later change again. But I will see how to make changes small. Maybe I back with the first solution accepting both Slug interface

@eerison eerison force-pushed the feature/1713-rework-replace-slugify-to-symfony-string branch 9 times, most recently from 261d840 to 9d6aa9e Compare October 26, 2025 18:11
@eerison eerison marked this pull request as ready for review October 26, 2025 18:23
@eerison
Copy link
Contributor Author

eerison commented Oct 26, 2025

@VincentLanglet could you take a look.

I just extracted the fixUrl logic from PageManager to FixPageUrlService, and yes I keeped 2 classes in BC layer.

self::class,
FixPageUrlInterface::class,
), \E_USER_DEPRECATED);
$fixPageUrl = FixPageUrlSlugifyFactory::create($fixPageUrl);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this factory could be removed, since it is used only here and it won't be reused in the code. it will be like this

$fixPageUrl = new FixPageUrlService(new SluggerSlugifyAdapter($slugify));

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you're already planning to pass a Symfony slugger to this service, we could already have a small change of behavior here, so I don't think we have to force the use of sluggify here, you could

(new FixPageUrlService(new AsciiSlugger()))->fix()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well it will make the things easier, I do not need to keep support for slugify.

But don't you think we should keep an option to use Slugify in case someone find an issue and want to keep the old way?

or if someone want to use the old version, they should implement an SlugifyAdapter in their side?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In next major we will remove sluggify anyway so if someone encounter an issue with the change it's better to fix it instead of keeping slugify support

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed!

@eerison eerison changed the title Feature/1713 - Replace slugify for symfony string Feature/1713 - Replace slugify to symfony string Oct 26, 2025
@eerison eerison force-pushed the feature/1713-rework-replace-slugify-to-symfony-string branch 2 times, most recently from ab6ed87 to 181d376 Compare October 26, 2025 18:34
string $class,
ManagerRegistry $registry,
private SlugifyInterface $slugify,
private SlugifyInterface|FixPageUrlInterface $fixPageUrl,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not changing this signature to

private SlugifyInterface|SluggerInterface

?

Either it make sens to introduce a FixPageUrl service and this should be done in a separate PR in which the name will be challenged, either it is not needed and we could simplify this pr

Copy link
Member

@VincentLanglet VincentLanglet Oct 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently,

  • I see no reason to introduce a FixPageUrlInterface because we don't plan having multiple implementation
  • PageManager::fixUrl is basically useless since you can call FixPageUrl::fix directly (Which is not a bad thing but then the fixUrl method could be deprecated and the service injection)

Copy link
Contributor Author

@eerison eerison Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private SlugifyInterface|SluggerInterface

if you see in my first try, I added some if statement to check which interface I am getting, and It makes the code more complex.

edit: those managers are like repositories: https://github.com/sonata-project/sonata-doctrine-extensions/blob/2.x/src/Entity/BaseEntityManager.php. and this logical should be in other layer.

Either it make sens to introduce a FixPageUrl service and this should be done in a separate PR in which the name will be challenged, either it is not needed and we could simplify this pr

But don't you think this PR is simple enough to review? I basically extracted the logical and I am injecting it.

I see no reason to introduce a FixPageUrlInterface because we don't plan having multiple implementation

we do not plan to have multi implementation in our code. But it will help the devs to override the code if they need.

PageManager::fixUrl is basically useless since you can call FixPageUrl::fix directly (Which is not a bad thing but then the fixUrl method could be deprecated and the service injection)

yep that is true. but I am planning to deprecate this in other PR.

@eerison eerison force-pushed the feature/1713-rework-replace-slugify-to-symfony-string branch 2 times, most recently from cbad503 to dab31e4 Compare October 27, 2025 11:52
@eerison eerison force-pushed the feature/1713-rework-replace-slugify-to-symfony-string branch from dab31e4 to 729d077 Compare October 27, 2025 11:54
@eerison eerison force-pushed the feature/1713-rework-replace-slugify-to-symfony-string branch from 729d077 to c6205ac Compare October 27, 2025 11:57
use Sonata\PageBundle\Service\Contract\FixPageUrlInterface;
use Symfony\Component\String\Slugger\SluggerInterface;

final class FixPageUrlService implements FixPageUrlInterface
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should go with

final class PageFixer impelments PageFixerInterface
{}

and a method PageFixerInterface::fixUrl

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as it is a generic name, probably it will contain more methods with more fix. then you prefer have everything centralized in one place, even if it increases for 3 or 5 methods. and if we see it is necessary we refactor.

I do not have problem to change to PageFixer I just want to get your idea :). it will help for future PRs 😄

Copy link
Contributor Author

@eerison eerison Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

other question:

without suffix Service? if I keep inside of Service it will be different of other classes that already exist.

edit: it is mixed, there are services inside of src/Page/Service, src/Bock and src/Service

edit 2: I will keep with Service suffix as others services uses the same way, is it ok?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally hate the suffix service, didn't know some of the had.
On the opposite, other service like PageManager don't have such suffix.

We could create a folder Fixer ? with:

src/Fixer/PageFixerInterface
src/Fixer/PageFixer

WDYT ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in src/ level we should keep things like

  • Adapter
  • Bridge
  • Serializer
  • Http
  • Runtime
  • Service
  • Listener

etc I guess you know what I mean 😄 .. Fixer does not sound good IMO in src/ level.

I guess inside of Services fits good, But wihout Suffix, maybe we need to decide to keep or not Suffix.

well the problem in not using suffix, is it is in PSR for others things like MyCodeInterface.

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

Successfully merging this pull request may close these issues.

Switch cocur/slugify to symfony/string

2 participants