Skip to content

Initial work on enabledByOwner - #18152

Draft
brandonkelly wants to merge 2 commits into
5.xfrom
brandon/pt-2994-enabledbyowner-element-query-param
Draft

Initial work on enabledByOwner#18152
brandonkelly wants to merge 2 commits into
5.xfrom
brandon/pt-2994-enabledbyowner-element-query-param

Conversation

@brandonkelly

Copy link
Copy Markdown
Member

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

@linear

linear Bot commented Dec 8, 2025

Copy link
Copy Markdown

@brandonkelly

brandonkelly commented Dec 9, 2025

Copy link
Copy Markdown
Member Author

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:

  1. Create an enabled entry with a Matrix field.
  2. Create a draft for the entry.
  3. Disable the owner entry draft.
  4. Create a new nested entry within the Matrix field. (enabledByOwner = false)
  5. Enable the owner entry draft. (Nested entry’s enabledByOwner value is left alone as false because $element isn’t canonical.)
  6. 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:

  1. we call updateNestedEnabledByOwnerValues() every time an element is saved, regardless of whether its status changed; or
  2. we have a way of tracking primary element owners within the elements_owners table, so we know which nested elements’ enabledByOwner values 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.

Base automatically changed from 5.9 to 5.x January 20, 2026 18:06
…dbyowner-element-query-param

# Conflicts:
#	src/services/Elements.php
Copilot AI review requested due to automatic review settings August 4, 2026 02:00
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

This PR had conflicts with 5.x. Claude attempted an automatic resolution and pushed a merge commit. Please review the merge commit carefully before approving/merging — automated conflict resolution can silently pick the wrong side of a logic change.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds initial support for an enabledByOwner element query parameter by introducing an elements_sites.enabledByOwner column and plumbing it into element queries and element saving/propagation.

Changes:

  • Adds enabledByOwner to ElementQueryInterface/ElementQuery, filtering results via elements_sites.enabledByOwner.
  • Adds enabledByOwner column + index to installs and a new migration.
  • Starts tracking status changes during element saves to trigger recalculation of nested enabledByOwner values.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/services/Elements.php Tracks enabled-status changes and attempts to initialize/update enabledByOwner during element/site saves and propagation.
src/records/Element_SiteSettings.php Updates record docblock to include the new enabledByOwner property.
src/migrations/m251208_193926_enabledByOwner.php Adds the enabledByOwner column and index to elements_sites.
src/migrations/Install.php Ensures new installs create the enabledByOwner column and index.
src/elements/db/ElementQueryInterface.php Adds the enabledByOwner() query API contract.
src/elements/db/ElementQuery.php Implements enabledByOwner() and applies the filter during query preparation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/services/Elements.php
Comment on lines +4431 to +4435
private function updateNestedEnabledByOwnerValues(int $elementId, int $siteId, bool $enabledByOwner): void
{
// update nested elements' enabledByOwner values,
// but only if they are primarily owned by this element (recursively)
// ...
Comment thread src/services/Elements.php
* @param bool $saveContent Whether the element’s content should be saved
* @param bool $statusChanged Whether the element’s `enabled` status just changed
* @param Element_SiteSettingsRecord|null $siteSettingsRecord
* @retrun bool
Comment on lines +1736 to +1738
if ($this->enabledByOwner) {
$this->subQuery->andWhere(['elements_sites.enabledByOwner' => true]);
}
Comment on lines +16 to +20
public function safeUp(): bool
{
$this->addColumn(Table::ELEMENTS_SITES, 'enabledByOwner', $this->boolean()->notNull()->defaultValue(true)->after('enabled'));
$this->createIndex(null, Table::ELEMENTS_SITES, ['enabledByOwner'], false);
return true;
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