Validate in ValidHierarchyReferenceConstraintValidator should bypass non default entity revisions

Issue information

From user: tannguyenhn

Contribution record

Fork management

Problem/Motivation

This entity node cannot be referenced as it is either a child or the same entity.

Steps to reproduce

Setup a simple workflow with Draft, Needs Review, Published, Archived.
In Basic page node type enable "Create new revision" in publishing option and add field_parent as an Entity reference hierarchy field.

Step 1. Create 'Page Test' then save daft.
Step 2. Create 'Page Test 1' and in field_parent select 'Page Test' then save daft.
Step 3. Create 'Page Test 2' and in field_parent select 'Page Test' then save daft.
Step 4. Edit 'Page Test 2' and in field_parent remove 'Page Test' then save draft.
Step 5. Edit 'Page Test' and in field_parent select 'Page Test 2' then try to save the node => The error show up in field_parent field with message "This entity node cannot be referenced as it is either a child or the same entity."

Proposed resolution

We may need to update validate method in ValidHierarchyReferenceConstraintValidator to exclude non default revisions of children.
Same what we did with loadEntitiesForTreeNodesWithoutAccessChecks in EntityTreeNodeMapper.

Remaining tasks

User interface changes

API changes

Data model changes

Edited by drupalbot
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information