Problem/Motivation

Group types have a configuration that says authors automatically become members of the group they created. This is good, but the fact that it also happens for programmatically created groups is bad. Our test set-ups are overly complicated because of it and migrations are a pain in the ass.

Steps to reproduce

N/A

Proposed resolution

We need to make this a "create form only" thing, so that calls to our API do not magically behave different depending on what was configured on the group type. So the configuration option remains, but it only applies to form submission.

Remaining tasks

  1. Make this behavior form-only
  2. Write change record
  3. Adjust tests that relied on old behavior

User interface changes

N/A

API changes

No longer create members when group is created through code.

Data model changes

N/A

Issue fork group-3526265

Command icon 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

kristiaanvandeneynde created an issue. See original summary.

kristiaanvandeneynde’s picture

Okay I just realized we can kill the wizard with this approach + #3499398: Create a new editor flow that does not involve wizards or custom pages

First of all we will need to remove the wizard, but not with the automatic selection of the group from the other issue. This can be done as follows:

  1. Adjust GroupRelationshipCardinalityValidator so it works with new referenced entities
  2. Create a service that attaches (part of) GroupRelationship form to another Group or entity form. This will only attach the form if there are any custom fields on it that are accessible.
    • If it can't attach a form, it will still attach a submit handler that creates a blank GroupRelationship (GR) entity with either the newly created Group or groupable entity added to it.
    • If it can attach a form, we attach a validation handler and submit handler along with the form:
      • Validation handler builds the original form's entity and assigns it to the GR's correct reference's "entity" property. It then calls validate() on that and flags violations on the GR subform.
      • Submit handler builds and saves the original form's entity, then assigns that to the GR it builds and saves the GR.
  3. Double check that cardinality is properly reported even if fields for group and entity are hidden. Should be fine because we call $entity->validate() ourselves
kristiaanvandeneynde’s picture

We also need to make sure that, when we're on a config form that got modified by our service, we do not call ConfigWrapperStorage->wrapEntity() during the form validation step as that actually saves a ConfigWrapper in the system for a config entity that may not get saved after all. It should be harmless if that happens, but better safe than sorry.

We should instead manually create one so that it has isNew() still set. It's only for validation purposes, so the wrapper should never get saved.

kristiaanvandeneynde’s picture

Okay the PoC now works for group forms.

Still need to check a bunch of stuff, but the gist of it is that whatever is configured in the relationship's form display will be shown inline in the group form. This gives some level of control over the whole thing. Probably should also hard-code language to whatever the parent form specified.

This does mean that any hook_form_FORM_ID_alter for the group relationship form will not apply here. That's an unfortunate drawback.

kristiaanvandeneynde’s picture

Okay, works for both entities and groups now. Also tested with all relationship fields hidden.

So this needs:

  • Tests
  • Option from group type to "use wizard" removed + update hook
  • Option from relation type to "use wizard" removed + update hook

But so far it's looking very good and the code is a lot cleaner this way. No more temp store and wizard stuff.

kristiaanvandeneynde’s picture

Managed to work on this a bit, new status:

  1. Tests
  2. Option from group type to "use wizard" removed + update hook
  3. Option from relation type to "use wizard" removed + update hook
kristiaanvandeneynde’s picture

All green! Just need to add the helper method now to easily figure out if a form was enhanced and then we are good to go.

kristiaanvandeneynde’s picture

Title: Disallow automatic membership outside of form approach » Disallow automatic membership outside of form approach and remove wizard workflow

Re #3 (Yes, I am talking to myself): Wrappers are automatically created in RelationshipEntityReferenceItem, so we're good.

Also, this blew up in size way more than I thought and normally I'd split this up into multiple issues. But I really don't feel like with the little time I have to spend on it and I'm basically alone at this, so I've decided to let this one slide. The change records will make things clear.

Let's get this show on the road

kristiaanvandeneynde’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.