Marco
Marco

Reputation: 2338

Prepopulating group_audience field in Drupal 7 (Organic Groups)

I'm trying to get the prepopulate module to work with og with little success. From what I understand I can do ?edit[group_audience]=123, and by going through the code it seems the prepopulate plugin does what it is supposed to, and sets the dropdown #value to 123, but for some reason this doesn't work at all.

I've also found some information saying that it is possible to prepopulate the field using ?gids[]=123, has anyone had success with this, or has a real proper solution?

Upvotes: 2

Views: 2907

Answers (5)

hanksterr7
hanksterr7

Reputation: 105

For Drupal 7, with og 7.x-2.1, you need to have the entity reference prepopulate module installed (and follow the instructions in its readme). Once you do that, then the rest works like magic. Without that module installed/enabled, nothing happens when you try to do what is below. This url achieves the desired result of pre-poulating og_group_ref field with the group with id 1135: http://[site]/node/add/group-post?og_group_ref=1135

Upvotes: 0

Jeremy Edgell
Jeremy Edgell

Reputation: 51

So... the right way to do this for D 7.22 and OG 7.x-2.1 is:

node/add/[content-type-machine-name]?og_group_ref=[group-id]&destination=node/[group-id]

The above answers did not work for my setup.

See how I wasted my Sunday on this here: Drupal Organic Groups Pre-populated Audience Field

Upvotes: 2

geek-merlin
geek-merlin

Reputation: 1890

By appending ?gids[]= to your node/add URL, you can specify the group audience. By throwing in a comma-delimited list of nids, you can specify multiple audiences.

Upvotes: 0

Aaron Krieshok
Aaron Krieshok

Reputation: 9

Don't need the prepopulate module:

?gids_group[]=123

Found this in the Organic Groups readme:

You may craft your own URLs which produce useful behavior.

For example,

node/add/group-content?gids_node[]=4 

will add a select the group with node ID 4, in the node form.

The prefixed entity can change to indicate other entity types allowing crafting the URL and you can have multiple variables, for example,

node/add/group-content?gids_node[]=4&gids_user[]=3&gids_group[]=5,6,7

The above URL will select the group with node ID 4, and the group with user ID 3, and the groups with the unique group ID 5, 6 and 7. Note that the actual entity of group ID 5, 6 and 7 can be any entity (e.g. nodes or users).

Upvotes: 0

DuaelFr
DuaelFr

Reputation: 395

Did you try ?edit[group_audience][]=123 ?

Group audience is a multiselect box so it is possible that you need to use this syntax that allow to set multiple values.
?edit[group_audience][]=123&edit[group_audience][]=42&edit[group_audience][]=1

Upvotes: 0

Related Questions