Initial work on enabledByOwner
Description
Adds a new enabledByOwner element query param, which maps to a new elements_sites.enabledByOwner column. The column keeps track of whether the element/site’s owner element is enabled (recursively).
Related issues
- #18151
A little stumped on the most efficient way to bulid out the Elements::updateNestedEnabledByOwnerValues() method. I was thinking it could reference the elements_owners table directly to find nested elements, and be called recursively when nested enabledByOwner values differ from the passed-in $enabledByOwner value. But we don’t want to do that for nested elements that aren’t primarily owned by the saved element. E.g. if you create a draft and its nested element ownerships are duplicated for the draft, then disabled the draft, you wouldn’t want the nested elements’ enabledByOwner values set to false.
I considered only calling updateNestedEnabledByOwnerValues() when a canonical element is saved, but that would fail in the following situation:
- Create an enabled entry with a Matrix field.
- Create a draft for the entry.
- Disable the owner entry draft.
- Create a new nested entry within the Matrix field. (
enabledByOwner = false) - Enable the owner entry draft. (Nested entry’s
enabledByOwnervalue is left alone asfalsebecause$elementisn’t canonical.) - Apply the draft.
In this situation, the entry’s enabled value wouldn’t appear to have changed, so there would be no need to call updateNestedEnabledByOwnerValues(), so the nested entry’s enabledByOwner stays set to false.
So either:
- we call
updateNestedEnabledByOwnerValues()every time an element is saved, regardless of whether its status changed; or - we have a way of tracking primary element owners within the
elements_ownerstable, so we know which nested elements’enabledByOwnervalues to update for any given save.
Option 2 would be more performant, but would also require a new primary column added to elements_owners (or a primaryOwnerId column added to elements), and expect that all plugins that implement nested elements add a migration to set those values correctly for this feature to work.