Skip to content

Fix project config ordering for partial loaded elementSources entries#18719

Open
wvell wants to merge 1 commit intocraftcms:5.xfrom
SLASH2NL:5.x
Open

Fix project config ordering for partial loaded elementSources entries#18719
wvell wants to merge 1 commit intocraftcms:5.xfrom
SLASH2NL:5.x

Conversation

@wvell
Copy link
Copy Markdown

@wvell wvell commented Apr 15, 2026

Description

When project config is applied to a clean install, pending changes are currently
sorted only by path depth. That can cause sections changes to be processed
before related elementSources entries are fully constructed.

In our case, handleChangedSection() ends up reading element sources while an
elementSources entry only contains nested values like defaultSort and
tableAttributes, but is still missing scalar keys such as type. That leads
to:

Undefined array key "type"

in ElementSources::defineSources().

Before After
elementSources...defaultSort elementSources...defaultSort
elementSources...tableAttributes elementSources...tableAttributes
sections...siteSettings elementSources...0
elementSources...0 sections...siteSettings
sections...entryTypes sections...entryTypes

Before this change, sections...siteSettings could run before the parent
elementSources...0 entry had been fully applied. After this change, all
elementSources paths are processed first, so section change handlers never
observe partially-built element source configs.

This change sorts pending changes by top-level config key first, and then by
depth within each group.

A minimal regression test has been added to reproduce that failure mode.

Related issues

#18720

Applying project config to a clean install only sorted keys by depth.
This allowed `sections` changes to run before related
`elementSources` entries were fully built. Resulting in the error:

    In ElementSources.php line 147:

      Undefined array key "type"

Sort pending changes by top-level key first, then by depth within each
group. This makes sure only complete elements are applied.
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.

1 participant