cms
cms copied to clipboard
Publishing new entries with custom title format ends in infinite loop
Bug description
I have a collection with a custom title format setup. In the blueprint, I added two text fields ({title_intro} and {title_main}) and deleted the inital title field. When I save the blueprint, the title field gets automatically introduced again as type: hidden with required: false.
As far as I understand, thats what I would want. A hidden title field and a custom title format, which I can then call with the {{ title }}
tag in the frontend. This setting worked fine in "statamic/cms": "3.2.*"
Now with 3.3.4, whenever I then try to create a new entry and save the draft or publish the entry, I end up in an infinite loop. I can see the php-fpm system process gathering memory infinite as well.
How to reproduce
- Setup custom title format in pages collection
- Add two custom text fields to the blueprint, delete title field and save the blueprint.
- Use the two text fields as custom title format like ```{title_intro} {title_main}````
- Create a new entry and save draft or publish it.
I have reproduced it in a fresh install here: https://github.com/vanillavillage/statamic-issue-5757
Logs
No response
Versions
Statamic 3.3.4 Pro Laravel 8.83.7 PHP 8.1.4 No addons installed
Installation
Fresh statamic/statamic site via CLI
Antlers Parser
regex (default)
Additional details
No response
I have fiddled around some more and I have the very strong assumption, that the problem lies within the generation of the slug. Or in other words, when I enter a slug by myself (which is kind of my workaround atm), the saving and publishing process goes quick and successful.
After some research I found that this can be caused if last_modified
or updated_at
keys are used when collecting the augmented data. In either case for the new entry, it will call this: https://github.com/statamic/cms/blob/3.3/src/Data/ExistsAsFile.php#L71
For the new entry, this will then get to here:
https://github.com/statamic/cms/blob/3.3/src/Entries/Entry.php#L351
With initialPath
being null, it will then call buildPath
, which then gets us to this slug()
call here:
https://github.com/statamic/cms/blob/3.3/src/Entries/Entry.php#L369
which will trigger the recursion.
Interestingly, attempting to add those keys to the except
call here https://github.com/statamic/cms/blob/3.3/src/Entries/Entry.php#L790 does not resolve the issue. However, explicitly setting those two values if they don't exist before calling the augmented()
method does:
if ($this->has('last_modified') == false) {
$this->set('last_modified', Carbon::now());
}
if ($this->has('updated_at') == false) {
$this->set('updated_at', Carbon::now());
}
I am confronted to this very annoying problem too. I had opened a Discussion, as I was not so sure if it was a bug or just a project problem. https://github.com/statamic/cms/discussions/6785
I am super interested in any workable solution, as I am working on a projet supposed to go live very soon, and that relies completely on auto-generated titles.
Edit: Reading both these Issues https://github.com/statamic/cms/issues/6071 and https://github.com/statamic/cms/issues/5757 made me rethink the necessity of having a slug, so I turned the slug generation off, deleted the slug Field, and it seems to work so far.
slugs: false
title_format: '{eleve:title}'
route: '/{mount}/{semestre}/{title}-{id}'
It is a bit annoying to have the Entry save with its Id as file name… but at least I have a working project. I'll have to run more intensive testing, and I hope it will not come and bite me later 🤞🏼
So, FWIW, per my observations: slug + "normal" user generated title + route: ✅ slug + title_format + route: ❌ title_format + route, without slug: ✅ slug + title_format, without route: ✅