OG Audience field selection handler resets from ‘og:default’ to ‘default:node’ on field settings save

Created on 18 March 2025, 15 days ago

Problem/Motivation

In a fresh install of the Organic Groups (OG) module, creating a group and a group content type with the og_audience field (which uses the og_standard_reference field type) results in a field instance being generated with the og:default selection handler.

However, when navigating to the field in the Field UI and saving the field settings, the handler is replaced with default:node. This also forces the user to select a bundle because:

  • The available group types are not filtered.
  • The og:default handler is not presented in the UI.

This behavior is unexpected and suggests an inconsistency in how the selection handler is initialized and persisted.

Steps to reproduce

  1. Install the Organic Groups module in a fresh Drupal instance.
  2. Create a group content type and add an og_audience field.
  3. Observe that the field instance uses the og:default selection handler.
  4. Navigate to Admin → Structure → Content types → (Your group content type) → Manage fields.
  5. Edit the og_audience field settings and save.
  6. The selection handler changes from og:default to default:node, forcing the selection of a bundle.

Proposed resolution

  • Determine whether og:default should be used as the initial selection handler or if default:node should be applied from the start.
  • Consider extending the default selection handlers at runtime instead of relying on og:default.
  • Add explicit OG selection handlers similar to those in Drupal 7:
    • og_non_member_post: Allows selecting group nodes that a user is not a member of.
    • og: Restricts selection to group nodes where the user is a member.
  • Ensure that the selection handler does not unexpectedly change when saving field settings.

Remaining tasks

  • Investigate why og:default is being replaced by default:node.
  • Decide whether OG should override the selection handler at runtime rather than during field creation.
  • Implement missing selection handlers from OG in Drupal 7.
  • Add test coverage to verify the correct handler behavior before and after saving field settings.

User interface changes

  • Modify the Field UI to properly present and persist the og:default handler.
  • Add missing OG selection handlers to the selection UI.

API changes

  • Ensure OG extends the correct selection handler instead of modifying it unexpectedly.
  • Introduce additional OG-specific selection handlers.

Data model changes

  • No direct database schema changes, but field configuration behavior needs review and may need config update.
🐛 Bug report
Status

Active

Version

2.0

Component

og.module

Created by

🇨🇦Canada joelpittet Vancouver

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

Comments & Activities

  • Issue created by @joelpittet
  • 🇮🇱Israel amitaibu Israel

    A bit of context, and then I'll try to answer what I know :)

    The reason we have the OG field, is that we could check for an existing of such a field instance, to determine if the node (or any other entity) is a group or group content.

    Next, by having the OG field, we can create Selection handlers that would target only this field. That is, by knowing it's an OG reference field, then the selection handler already knows it should show only references to entities that are OG Groups.

    > Investigate why og:default is being replaced by default:node.

    Sounds like a bug.

    > Decide whether OG should override the selection handler at runtime rather than during field creation.

    It's better on field creation. We should follow as much as we can what Drupal core is doing, and avoid magic. The sin of the OG complex field is that it's trying to do that. Show both the "My groups" and the "Other groups". But if it was a "regular" ER (entity reference) field, we would achieve it by having some custom code that is as simple as creating an outgroup select list, grouped by "member" or "non-member".

    > This also forces the user to select a bundle because:

    Like a regular ER field, we should also let the user select a bundle. As one field could reference Group1 bundles, and another could reference Group2 bundles.

  • 🇨🇦Canada joelpittet Vancouver

    @amitaibu, thanks for the context. Just to clarify, when the field UI saves, it saves/exports the default:node selection handler, when it's created it's og:default. Although you mentioned it might be a bug, I believe it’s working as intended—that it should export and create the handler that way (currently creates the field as og:default).

    The result would be that the audience field is created with a new handler that only allows selecting groups where the user is a member (with the OG admin exceptions), while default:node continues to work like the D7 og_non_member_post. This approach keeps the logic simple and ties it directly to the site builder’s explicit choice. What do you think?

  • 🇨🇦Canada joelpittet Vancouver

    @amitaibu alternative I discussed with @ramil g, we can force the og:default in the field UI, and maybe strip out the option to select views or other ER entity reference selection handlers that are inherited? Then we create a separate OG specific handler for og_non_member_post.

    For illustration purposes this is what I am talking about regarding this bug.

    Before save:

    After save:

    D7

  • 🇮🇱Israel amitaibu Israel

    Yeah, it sounds like a bug.

    We should only show OG-specific handlers that are valid for OG reference fields.

  • 🇨🇦Canada joelpittet Vancouver

    Thanks for the call today. I realized during the call og_non_member_post was custom in D7 on our site, so we can just implement that.

    We will handle the bug (I think @ramil g did it already) in 📌 OG reference field widget update: MR #570 did not properly merge, leaving og_complex in place Active .

    I will close this as works as designed.

Production build 0.71.5 2024