Commit 6ef2f9b
fix(core): return full entry object from invokeEvent instead of just data (#7667)
The `invokeEvent` function in registry.js was returning only the data
payload (`_data.entry.get('data')`) instead of returning the complete
entry object. This caused entry metadata fields (slug, path, meta, etc.)
to be lost during event processing, particularly affecting file
collections that rely on slug for file lookups.
When `invokePreSaveEvent` was called during entry persistence:
1. Entry starts with all metadata: slug, path, meta, isModification, etc.
2. `invokeEvent` is called with the full entry object
3. `invokeEvent` returns ONLY the data payload, stripping metadata
4. Calling code replaces the full entry with just the data payload
5. Downstream operations like `entryToRaw` receive incomplete entry
6. `fieldsOrder` method fails trying to match slug to file definitions
This manifested as errors like:
- "No file found for undefined in [collection]"
- "TypeError: can't access property 'toJS', file is undefined"
The bug was introduced in commit 0d7e36b (January 31, 2020) and has
existed for ~5 years, but was only exposed in recent versions (3.2.0+)
when file collection persistence logic started calling `invokePreSaveEvent`
and fully relying on its return value to update the entry draft.
Changed `invokeEvent` to return `_data.entry` (the complete entry object)
instead of `_data.entry.get('data')` (just the data payload).
This preserves all entry metadata through the event handler chain, ensuring
that callers like `invokePreSaveEvent` receive the complete entry object
with all properties intact.
Verified fix resolves file collection publishing issues where:
- Custom widgets modify entry data during save
- File collections with single files rely on slug matching
- Entry metadata must be preserved through preSave event handlers
Fixes #[issue-number-if-exists]
fix(core): test returning full entry when invoking preSave handler
Co-authored-by: Yan <61414485+yanthomasdev@users.noreply.github.com>
Co-authored-by: Martin Jagodic <jagodicmartin1@gmail.com>1 parent 50986a0 commit 6ef2f9b
3 files changed
Lines changed: 69 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
391 | 391 | | |
392 | 392 | | |
393 | 393 | | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
394 | 456 | | |
395 | 457 | | |
396 | 458 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
200 | 200 | | |
201 | 201 | | |
202 | 202 | | |
203 | | - | |
| 203 | + | |
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
| |||
233 | 233 | | |
234 | 234 | | |
235 | 235 | | |
236 | | - | |
| 236 | + | |
237 | 237 | | |
238 | 238 | | |
239 | 239 | | |
| |||
254 | 254 | | |
255 | 255 | | |
256 | 256 | | |
257 | | - | |
| 257 | + | |
258 | 258 | | |
259 | 259 | | |
260 | 260 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
257 | 257 | | |
258 | 258 | | |
259 | 259 | | |
260 | | - | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
261 | 264 | | |
262 | 265 | | |
263 | 266 | | |
| |||
0 commit comments