Skip to content

Conversation

@i-just
Copy link
Contributor

@i-just i-just commented Oct 10, 2025

Description

Issue:
Field layout elements with non-existent fields are still being added to the layout, causing them to never get deleted from the project config.

Steps to reproduce:

  • clean 5.8.18 installation
  • create two plain text fields
  • create a section with an entry type that uses both those fields and the default title field
  • check the project config file for the entry type and note that it has layout elements for the title field and both plain text fields
  • delete one of the plain text fields via control panel > Settings > Fields (do not edit the entry type at this point)
  • check the project config file for the entry type and note that it has layout elements for the title field and both plain text fields; the layout element for the deleted field will not have the comment with the field’s name next to fieldUid value
  • edit the entry type, make no changes and save
  • check the project config file for the entry type and notice that nothing has changed - it still has 3 layout elements in it

When we get the field layout, we create tabs for it, and each tab gets all the elements it’s supposed to have.

Up until 5.8.12, when Fields->createLayoutElement() was called from FieldLayoutTab->setElements(), the FieldNotFoundException was thrown if the field couldn’t be found from the CustomField->setFieldUid() method.

The changes in e80ca1b moved the throwing of the FieldNotFoundException to the CustomField->getField() method, which means it’s never really thrown when rendering, e.g. entry type page with its field layout. This causes the layout element for the ghost field to be included in the field layout, which in turn means that it’s never removed from the project config.

Fix:
When a layout element is created for a CustomField, check that the field exists, and if not, don’t include it in the field layout tab’s elements.

Related issues

caught while working on a Feed Me issue (craftcms/feed-me#1679)

@i-just i-just requested a review from brandonkelly October 10, 2025 14:43
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.

2 participants