Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested element DX improvements #15894

Merged
merged 3 commits into from
Oct 15, 2024
Merged

Conversation

brandonkelly
Copy link
Member

Description

Adds NestedElementQueryTrait, which can be added to element query classes to provide fieldId, ownerId, primaryOwnerId, allowOwnerDrafts, and allowOwnerRevisions params.

class MyElementQuery extends ElementQuery
{
    use NestedElementQueryTrait;

    protected function beforePrepare(): bool
    {
        // ...

        $this->applyNestedElementParams('elementable.fieldId', 'elementtable.primaryOwnerId');
    }
}

Also adds NestedElementTrait::saveOwnership(), which can be called from elements’ afterSave() methods to save their ownership data in the elements_owners table.

class MyElement extends Element
{
    public function afterSave(bool $isNew): void
    {
        // ...

        $this->saveOwnership($isNew, '{{%elementtable}}');
    }
}

Related issues

@brandonkelly brandonkelly merged commit eb42e97 into 5.5 Oct 15, 2024
@brandonkelly brandonkelly deleted the feature/nested-elemnet-traits branch October 15, 2024 17:41
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