Relate Content to a Group feature when creating a node outside a group In my drupal site, I'm using the Group module.

My problem:


  I created a regular Drupal node type, let's call it userpost
  I created a group type called "usergroup"
  The content type "userpost" is also installed as a group node of group type "usergroup"


Is there a way to put a reference field or something similar into my "regular" node form for my content type called userpost? So that it's possible to (optional) relate a node during creation, to one (or more) group(s) at the same time?

In the admin interface of a group it's possible to relate existing content to a group. This kind of reference field I would like to place into my node creation form :)

Thanks for any hint in advance.

Best regards
Phil

P.S. I opened for this problem an issue at Drupal.org too.
Well, if I understand your problem correctly, you could just add an entity_reference field to your node type 'userpost' via admin toolbar. Go to Structure->Content types->userpost->Manage fields->Add field->Choose Reference (other)->Select Group and set cardinality to whatever you want.

This would allow you to add group references when you create a new node of content type userpost

Update
What I described adds a reference from a node to one or multiple group(s) via a new field, it does NOT add this node as a group-content to your group(s). It depends what you are trying to achieve? If you want to add your node as a group-content and you want to do this via the node creation form, you need one more extra step. You can implement a hook_ENTITY_TYPE_insert(). From there get the group(s) that you entered to your node field (from $node), $groups = $node-&gt;get('field_groups') and add the $node as group_content to each group, similar as done in the answer you linked.