Skip to content

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

@bencroker

Description

@bencroker

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions