Skip to content

Nested element DX improvements#15894

Merged
brandonkelly merged 3 commits into5.5from
feature/nested-elemnet-traits
Oct 15, 2024
Merged

Nested element DX improvements#15894
brandonkelly merged 3 commits into5.5from
feature/nested-elemnet-traits

Conversation

@brandonkelly
Copy link
Copy Markdown
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