Problem/Motivation

As a content editor who wants to add a node to an EntityQueue, on the /node/[nid]/entityqueue page the buttons for adding to or removing from any queue returns the following notice:

The operation could not be performed for the following reasons:
This entity (taxonomy_term: 57) cannot be referenced.

Adding and removing from the Subqueue page DOES work (/admin/structure/entityqueue/[entityqueue-id]/[generated-entityqueue-subqueue-id])

Steps to reproduce

  • Enable Entityqueue and Entityqueue Smartqueue
  • Add a new Entityqueue with the type "Smart queue" (/admin/structure/entityqueue)
  • Select "Taxonomy term" and Entity type, and select a Taxonomy.
  • In the Entity Settings, select a content type
  • View content (of the selected type), go the EntityQueue tab, try to add to the generated queue(s)

In my use case, the Taxonomy used is only used for one Content Type, which is also selected in the Entityqueue configuration.

Proposed resolution

??? Is this a problem with the csrf_token? I've been poking/hacking, and it seems removing "_csrf_token:TRUE" from the routing prevents the error, but it doesn't make the buttons on a content's Entityqueue tab work.

Remaining tasks

TBD

User interface changes

TBD

API changes

TBD

Data model changes

TBD

Comments

Nels created an issue. See original summary.

nels’s picture

Issue summary: View changes
sadman’s picture

+1 on having this issue. I don't really have anything to add to the issue description. It perfectly describes the steps to produce the issue. If i create an Entityqueue of type with Smart Queue based on taxonomy term vocabulary. Our editors can not add or remove content items from the node edit page on the Entityqueue tab.

dpi’s picture

Version: 8.x-1.2 » 8.x-1.x-dev
Category: Support request » Bug report

Can confirm with EQ 1.6.

When trying to add a node entity in context to a queue via `/node/{nid}/entityqueue`, wherein the queues are a subqueue(smartqueue).

The subqueues represent taxonomy terms. They are permitted to link to Content (aka node)

The following message is displayed:

The operation could not be performed for the following reasons:
This entity (taxonomy_term: 123456) cannot be referenced.

I've traced this to what appears to be problems derived from the workaround hooks in entityqueue_smartqueue_entity_field_storage_info and/or entityqueue_smartqueue_entity_field_storage_info

When the validator attempts to determine the target entity type of the attached_entity entity reference field grafted onto the \Drupal\entityqueue\Entity\EntitySubqueue entity, it still thinks the target type is entity_subqeueu, not taxonomy_term.

Clues

An entity reference handler plugin is created in ValidReferenceConstraintValidator.php via $handler = $this->selectionManager->getSelectionHandler($value->getFieldDefinition(), $entity);. This method gets the target type from the field storage definition, not the field instance. The target type configuration property therefore is pointing to entity_subqueue not taxonomy_term.
ValidReferenceConstraintValidator.php calls $handler->validateReferenceableEntities($target_ids);

Eventually validateReferenceableEntities is called, and the ID validation is performed on the wrong table.

Suggested solutions

Either the field storage alters are reworked so it doesnt need to hack in a different entity type in order to work around int/string issues. Perhaps the project should migrate to use https://www.drupal.org/project/dynamic_entity_reference for the field storage to work around int/str in the same column.

Implement and configure a custom EntityReferenceSelection plugin, such that DefaultSelection is not used, which calls out to the undesired table.

dpi’s picture

Title: Smartqueue from taxonomy: The entity cannot be referenced » Entity subqueue tab: The entity cannot be referenced

Given above evidence I don't think this is specifically tied to taxonomy (though my example does reference terms)

slydevil’s picture

I ran into this issue, but my term is unpublished (using Content Moderation) and in my case I cannot add by using the entityqueue page or the tab.

slydevil’s picture

Maybe related to this ore issue - https://www.drupal.org/project/entityqueue/issues/2383903.

Fixed my issue by creating an entity reference view and swapping the Reference Method of the queue from Default to the view.

dpi’s picture

Yeah, changing the EntityReferenceSelection to use something else is going to allow you to reference more items. But theres a chance you'll be able to reference target entities that it shouldnt be able to. Such as different entity types or bundles.

I see the best way forward as implementing our own EntityReferenceSelection plugin.

uttam’s picture

Yes I was going through the entityqueue module and i feel that it would be nice if there is a option to select the content types for subqueues too.

mlncn’s picture

Priority: Normal » Major

Getting the same " This entity (node: 2005) cannot be referenced. " style errors for every unpublished piece of content in the queue.

User 1 does not have this problem. But there are no permissions that could be granted to allow referencing, which makes this a major permissions-related bug.

mlncn’s picture

Status: Active » Needs review
StatusFileSize
new1.14 KB

This fixes it for saving the whole entityqueue listing.

Have to admit i'm not sure of other cases.

amateescu’s picture

Priority: Major » Normal
Status: Needs review » Active

@mlncn, the problem you're bumping into is a core bug (#2973863: ValidReferenceConstraintValidator should not try to enforce data integrity on pre-existing references), and not related to this issue.