Group content entity_id target_bundles setting malformed

Created on 2 November 2020, about 4 years ago
Updated 11 August 2023, over 1 year ago

Problem/Motivation

The target_bundles setting of the entity_id field on the group content entity is not properly formed. The target_bundles setting should be an array where both the key and value are the machine name of the bundles. In GroupContentEnablerBase, an indexed array with the bundles as a value is used.

Steps to reproduce

I ran into into a problem when using Layout Builder on a paragraphs entity that was referencing a media entity that was group content. I don't think I can give the exact steps to reproduce, but when trying to manage the layout I got an exception in Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::generateSampleValue(). I tracked the source of the exception down to the target_bundles array being generated by Drupal\group\Plugin\GroupContentEnablerBase::getEntityReferenceSettings(). The generateSampleValue() method is using the key from target_bundles array for determining a random bundle to use as a sample. With group content, the key is an integer, not the bundle ID, and this causes an exception. Other non-group entityreference fields have target_bundle arrays with the bundle ID as both the key and the value.

Proposed resolution

In Drupal\group\Plugin\GroupContentEnablerBase::getEntityReferenceSettings(), change this:

$settings['handler_settings']['target_bundles'] = [$bundle];

to this:

$settings['handler_settings']['target_bundles'] = [$bundle => $bundle];

Remaining tasks

None.

User interface changes

None.

API changes

None.

Data model changes

None.

πŸ› Bug report
Status

RTBC

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States zengenuity

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