Problem/Motivation
Upgrading from 10.0 to 10.6 and trying to use an entity reference field on a node that references a config term we always get a validation error like:
"field_hazards.0.target_id: This entity (config_terms_term: hazards_uncharacterized_unknown) cannot be referenced.",
The entity reference field has this for the selection handler:
settings:
handler: 'default:config_terms_term'
handler_settings:
target_bundles: { }
auto_create: false
target_vocab: chemical_profile_hazards
this is also generating a warning in a DSM and log messages:
Deprecated function: mb_strtolower(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\Core\Config\Entity\Query\Condition->compile() (line 39 of core/lib/Drupal/Core/Config/Entity/Query/Condition.php).
This appears to come from the logic in \Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection::buildEntityQuery() that sets the ID to null if the target bundles is an empty arry:
// If 'target_bundles' is NULL, all bundles are referenceable, no further
// conditions are needed.
if (is_array($configuration['target_bundles'])) {
// If 'target_bundles' is an empty array, no bundle is referenceable,
// force the query to never return anything and bail out early.
if ($configuration['target_bundles'] === []) {
$query->condition($entity_type->getKey('id'), NULL, '=');
return $query;
}
Proposed resolution
override TermSelection::buildEntityQuery() to filter by vid against target_vocab
We already do this in a way in \Drupal\config_terms\Plugin\EntityReferenceSelection\TermSelection::getReferenceableEntities()
Remaining tasks
write fix add tests
User interface changes
n/a
API changes
n/a
Data model changes
n/a
Issue fork config_terms-3589028
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
pwolanin commentedfixing in 2.x only for now
Comment #4
pwolanin commentedAdding a bunch of cleanup, new tests, and handling broken permission strings
Comment #5
pwolanin commentedComment #6
heddnLGTM
Comment #8
pwolanin commented