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

[5.x]: ElementHelper::isDraft not working for nested elements #15303

Closed
bencroker opened this issue Jul 4, 2024 · 2 comments
Closed

[5.x]: ElementHelper::isDraft not working for nested elements #15303

bencroker opened this issue Jul 4, 2024 · 2 comments
Labels

Comments

@bencroker
Copy link
Contributor

What happened?

When a nested entry in a matrix field is modified, a draft is automatically created. When the draft is saved, however, calling ElementHelper::isDraft($element) returns false.

This appears to be caused due to getIsDraft() being called on the root element, rather than on the element itself.

return static::rootElement($element)->getIsDraft();

I imagine this could be solved as follows:

return $element->getIsDraft() || static::rootElement($element)->getIsDraft();

Note that the ElementHelper::isDraftOrRevision() and possibly also the ElementHelper::isRevision() method should be updated accordingly.

Steps to reproduce

  1. Listen for a save event on a nested entry in a matrix field.
  2. Modify the nested entry so that it automatically creates a draft (without hitting the save button).
  3. Check the value of ElementHelper::isDraft($element).

Expected behavior

ElementHelper::isDraft($element) should return true.

Actual behavior

ElementHelper::isDraft($element) returns false.

Craft CMS version

5.2.5

PHP version

No response

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

No response

@brandonkelly
Copy link
Member

Thanks for pointing that out! Fixed for the next Craft 4 and 5 releases.

@brandonkelly
Copy link
Member

Craft 4.10.5 and 5.2.6 are out now with that fix. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants