Problem/Motivation

This happens on both node save, and when adding a paragraph to a ERR field on a node.

When a user without the "bypass workbench access" permission attempts to save (I presume any) entity, with a section field that is empty a fatal error occurs:

 TypeError: Argument 1 passed to Drupal\\workbench_access\\AccessControlHierarchyBase::checkEntityAccess() must implement interface Drupal\\Core\\Entity\\EntityInterface, null given, called in /data/app/modules/contrib/entity_hierarchy/modules/entity_hierarchy_workbench_access/src/Plugin/Validation/Constraint/ValidEntityHierarchySection.php on line 62

This is due to $parent = $items->entity; assuming that a value is returned.

This also seems to occur when adding a new paragraph to an entity reference revisions field.

Proposed resolution

Add the violation if the field is empty and the "Deny access to unassigned content" flag is checked.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

acbramley created an issue. See original summary.

acbramley’s picture

Assigned: Unassigned » acbramley

Taking a stab at this now.

acbramley’s picture

Status: Active » Needs review
FileSize
1.35 KB

Here's a test which surfaces the error.

EDIT: Missed the title on the node, will fix in follow up with actual fix.

acbramley’s picture

FileSize
2.72 KB
1.33 KB
larowlan’s picture

+++ b/modules/entity_hierarchy_workbench_access/src/Plugin/Validation/Constraint/ValidEntityHierarchySection.php
@@ -59,8 +59,12 @@ class ValidEntityHierarchySection extends Constraint implements ConstraintValida
+        $this->context->addViolation($this->message);

Can we return here (in both cases) and avoid the elseif (I like to avoid using else, but I really really like to avoid using elseif)

Thanks

Status: Needs review » Needs work

The last submitted patch, 4: 2938432-4.patch, failed testing. View results

larowlan’s picture

Status: Needs work » Needs review
larowlan’s picture

Status: Needs review » Needs work

Just need to address the maintainer's personal penchant for avoiding elseif ;)

acbramley’s picture

Status: Needs work » Needs review
FileSize
2.73 KB
1.08 KB

Haha sure, I actually had it like this originally but thought elseif looked cleaner.

  • larowlan committed 1a8e593 on 8.x-2.x authored by acbramley
    Issue #2938432 by acbramley, larowlan: When saving an entity with an...
larowlan’s picture

Status: Needs review » Fixed

Fixed, rolling a new alpha

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.