Redhen Contact to User form embedding process and field_group support

Created on 29 March 2023, over 1 year ago
Updated 6 June 2023, over 1 year ago

Problem/Motivation

Field Group module doesn't catch the Redhen Contact form embedding process itself.
I'm trying to create field wrappers via Field Group on my "Account Registration" contact form display view mode, for the user register form.
I've added the wrappers, then go to "/user/register" and didn't see any effect.

Steps to reproduce

  • Create form display view mode that will be used to embed to user register form.
  • Go to "/admin/config/redhen/contact" and enable "Create a contact during user registration" checkbox, then set your view mode in the "Registration Contact Form" select.
  • Go to your view mode, add some test fields and wrap them via field group feature.
  • Go to User Register form and check result, you shouldn't see any field group element you added.

Proposed resolution

Add this code at the end of this function _redhen_contact_user_embed_contact_form().

  // Field Group process when module exist.
  if (\Drupal::moduleHandler()->moduleExists('field_group')) {
    $context = [
      'entity_type' => $contact->getEntityTypeId(),
      'bundle' => $contact->bundle(),
      'entity' => $contact,
      'context' => 'form',
      'display_context' => 'form',
      'mode' => $form_mode,
    ];

    field_group_attach_groups($form['redhen_contact_' . $contact->getType()], $context);
    $form['redhen_contact_' . $contact->getType()]['#process'][] = [
      FormatterHelper::class,
      'formProcess',
    ];
    $form['redhen_contact_' . $contact->getType()]['#pre_render'][] = [
      FormatterHelper::class,
      'formGroupPreRender',
    ];
  }

Additional odd behavior

The embedded part of the form has a default form wrapper (title "General Contact information" in my case).
Details element has a parameter '#open' => TRUE, but it displayed as closed when I test it with a code above.
So looks like we need an additional fix for this.

Thanks!

✨ Feature request
Status

Active

Component

redhen_contact

Created by

πŸ‡ΊπŸ‡¦Ukraine Dishvola

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

Comments & Activities

  • Issue created by @Dishvola
  • Assigned to gcb
  • πŸ‡ΊπŸ‡ΈUnited States gcb
  • πŸ‡ΊπŸ‡ΈUnited States gcb

    I wonder if we should just refactor the way "contacts on User forms" works, maybe by adapting functionality from entity reference and embedded entity form.

    This could take the form of a pseudofield for user forms that leverages the entity reference embed behavior.

Production build 0.71.5 2024