Term labels collected by PageContext are not fully controlled by mapped fields

Created on 6 December 2022, almost 2 years ago
Updated 27 August 2024, 3 months ago

Problem/Motivation

The settings UI maps taxonomy fields to page contexts. `Drupal\acquia_perz\Service\Context\PageContext` then creates a context string of term names from this mapping. However it uses the node term index to do this and only uses the selected field to determine which taxonomies from this index to allow. This will produce unexpected results in more complex entity reference setups. See Steps to reproduce for an example.

Steps to reproduce

  1. With a taxonomy, such as tags, create two entity reference views that return disjoint subsets of tags.
  2. Create two term reference fields, set_a and set_b, which target tags and each use one of the views created above.

The user would expect that if only set_a is used in a mapping that only the terms referenced in set_a would appear, but in fact the terms in set_a and the terms in set_b will be used.

Proposed resolution

Simplify the code to take advantage of EntityReferenceFieldItemListInterface::referencedEntities which loads all the referenced entities in one query, and collect the term labels.

Remaining tasks

PageContext::getAvailableFieldVocabularyNames and PageContext::getAvailableFieldVocabularyNames are left in place currently for comparision. They are unused in this revision and should be removed before merging if this approach is acceptable.

User interface changes

None

API changes

None

Data model changes

None

πŸ› Bug report
Status

Needs review

Version

4.1

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States fathershawn New York

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024