Slug generation different on CP and Frontend.
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 3.6k
- Forks
- 705
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 134
Description
Description
Im not sure if it is intended behaviour, I would doubt so, but the algorithm for slug generation on the control panel seems to differ to the createSlug function used in the ElementHelper for frontend requests.
From my understanding the ElementHelper uses the StringHelper to convert the string toKebabCase which uses self::toWords to then will split the string. This is where I believe the differences in the two algorithms occur. The ElementHelper algorithm seems to split the string by CamelCase where as the control panel algorithm does not. You can see the results of this in the steps to reproduce below:
Steps to reproduce
- In the control panel create a new entry with the title "EntryTest"
- When entering the title you will see the slug in the right hand side generate to "entrytest"
http://prntscr.com/n5tg6p - Create a new entry with the title "EntryTest" but this time from the frontend by making a request to the actionSaveEntry in the EntriesController.
- Now on the control panel review the generated slug on the new entry "entry-test"
http://prntscr.com/n5tk16
Additional info
- Craft version: 3.1.19
- PHP version: 7.2.14
- Database driver & version: MySQL 5.7.25
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/web/assets/cp/src/js/SlugGenerator.js, then compare its behavior with ElementHelper::createSlug in src/helpers/ElementHelper.php and the referenced StringHelper::toWords implementation. Reproduce the "EntryTest" case through the control panel and EntriesController actionSaveEntry; done means both paths generate the same slug.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, php
- Domain
- full-stack
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100