Issue with entity reference fields in D10

Created on 22 December 2023, 6 months ago
Updated 15 June 2024, 13 days ago

Problem/Motivation

There appears to be a change in how D10 handles entity reference fields in regards to token replacements. I'm using the patch from πŸ’¬ Is there any way to pass the token from the current paragraph to the view? Needs work in my situation, but I think this would occur with nodes as well. In my setup, I have an entity reference field on the entity where the content author can choose from available custom blocks in the system. If a block is selected, the id is passed as an argument to the view setup in the views reference field. If nothing is chosen, then the view falls back to the default. In D9 this works fine, but in D10 it looks like what's happening is that the replacement fails altogether. This causes the view reference field to try an pass the token text to the view argument. The NumericArgument class then tries to parse that to figure out the argument and operator, which also fails, causing it to try an assign a null operator to the view. That will generate this exception:

TypeError: Cannot assign null to property Drupal\views\Plugin\views\argument\ArgumentPluginBase::$operator of type string in Drupal\views\Plugin\views\argument\NumericArgument->title()

Steps to reproduce

Install D10 and this module.
Create a view that accepts an entity ID as a context argument.
Create a new content type with an entity reference field and a view reference field.
Set the view reference field to the view created above and to accept the entity reference field as an argument.
Create a new page of that content type, but leave the entity reference empty and the save content.
Attempt to load the page and you should receive the error above.

Proposed resolution

There may be more graceful ways to handle this, but one way to fix it is to simply check that a token replacement occurred after the replacement is attempted. If it didn't, then unset that argument. That's what this patch does.

πŸ› Bug report
Status

Needs review

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States jacobbell84

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024