Edit with SlugField does not work
Describe the bug When you create a field with SlugField, on new page is working, but when you try to change it after in an edit action, it's seems to not working.
To Reproduce
yield TextField::new('name');
yield SlugField::new('slug')->setTargetFieldName('name');
I don't know if it's a bug or a normal behavior,
Thank's in advance,
Yes, this is the intended behavior because changing the value of a slug usually means breaking URLs, etc.
But I think we could add a config option to allow updating the slug value whenever the related field changes.
I prepared PR for this issue (add another custom option then pass it and handle it in javascript) however when I tested it on my existing project I realized that we often handle slug using doctrine lifecycle events (to for example preserve unique or be sure that the slug will be constant for the whole page life). Other words this specific property depends highly on different parts of codes, not related to easyAdmin, so I'm worry if enabling it for edition will couse more trouble.
@eminjk Do you need help for this PR ? I can work on it
Well, as I said I don't think it's a good idea based on the nature of a slug.
There are two approaches - first one is about to follow the parent field or a kind of pattern (ex. title) and update whenever that field is changed. Second one is to treat slug as a constant value which is better for external (sharing) linking, maybe some SEO purposes.
The common way to handle slug is to do it on the entity level and there are at least two options - either use Doctrine Extension ( https://github.com/doctrine-extensions/DoctrineExtensions/blob/main/doc/sluggable.md) or use Doctrine Lifecycle Events.
SlugField generate slug using js library which simply track specified field (on a frontend side only). That kind of blockade of editing is also done in js. If you handle your slug inside Entity then the frontend part (form) doesn't matter - it will act exactly how it's configured and this is the situation I described before. In my project slug was configured as not updatable and the "magic" behind just overwrote any changes made by form. If we add allow_update option then the next issue will be about not updating slug even allow_update is set as true, which ofc also could be handled by bypassing another extensions, then next issue will be about losing uniqueness of slug which was working using extension but it stopped to once bypassed etc etc.
@javiereguiluz what do you think about it
@eminjk I'm using easyadmin for an headless CMS solution with nextjs, so when I change slug URL it's automatically changed too,
I don't especially need Seo, it's protected with password Access,
May be you could juste explain how I Can Do that and I override my JavaScript ?
Thanks in advance,