Hi

I am using OG Groups and Panels as you suggested in your video. It works very well! I have the following setup:
- Interest Group: This is a interest group that people can create and join
- Interest Group Board Entry: Similar to facebook Groups my in my Interest Groups people can post board entries

Using Panels and views I am able to display all my Board entries on my interest group page and also able to add a node add form for interest group board entries! The only problem I have now is that the users always have to choose the group audience. But it is obvious what audience it is, because they are already on the group page, so they should not choose this, but instead this shoud be filled automatically by the system.

A small example: I have two interest groups: Chess and Football. So if I am at the Football page and want to add a board entry, the system should automatically fill out the group audience with "Football".

Do you have any idea on how to do that?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

amitaibu’s picture

Status: Active » Fixed

You can add in your panels the plugin under "Organic groups" -- node links.

bochen87’s picture

Do you mean I should add a relationship "Group from OG context module" and then add the Content under Organic Groups -> "OG Content create links"?

This is not what I meant, because this will only add links on the page to create new content. But I have my content add form already on my OG Goup page. I need this content add form on my OG Group page to be already prefilled with the group audience

bochen87’s picture

I have added a picture. As you can see I have the node add form on my group page and the board entries below. The Groups Audience Field should be prefilled and the user should have the need to select it himself.

bochen87’s picture

Status: Fixed » Active

Sorry for spamming, but forgot to change the state to active...

amitaibu’s picture

Status: Active » Fixed

See the readme of og about building a URL

bochen87’s picture

Status: Fixed » Active

Hi, I saw this as well, but you can only do this if the form element is loaded. If for example I do not load the form element, then this function via the URL does not work. And I do not want my users having to see this or to select this every time. It is also not an option to hide this via CSS, as you can easily then manipulate this.

amitaibu’s picture

Status: Active » Fixed

Then you should use hook form alter.

Status: Fixed » Closed (fixed)

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

kclarkson’s picture

Status: Closed (fixed) » Active

@bochen87,

did you ever find a solution to your problem, besides "use hook form alter"?

Thanks,

bochen87’s picture

nope.

amitaibu’s picture

Version: 7.x-1.1-rc4 » 7.x-1.1
Status: Active » Closed (fixed)
kclarkson’s picture

Status: Closed (fixed) » Active

@bochen87

Is it possible for you to post your code that u used for this?

I have looked and tried the content links module but it still makes me select an audience.

In D6 the node reference URL widget worked great but have yet to find a D7 solution.

This would be a very handy add in module for people who are going to have tons of groups or subgroups

amitaibu’s picture

Version: 7.x-1.1 » 7.x-2.x-dev
Category: support » feature
Status: Active » Fixed

In 2.x branch, you can use Entityreference prepopulate module. For 1.x, you will need custom code, or use Prepopulate module.

Status: Fixed » Closed (fixed)

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

djween’s picture

Hi

I read through the README.TXT. Can someone please clarify:

Am I able to replace the group content audience field (group_audience) with a entity reference field that gets pre-populated with groups (either through URL params or view)? If so, do I need to name the field in the database as: "group_audience"

Thanks!

Scratch the above. I am using 7 1.x so seems I need to wait for 2 (using an entity reference would be amazing) or use pre-populate now.

adamtong’s picture

I would like to know to. My organice good content path is like "www.example.com/group/groupname", I have a block to with a link of "node/add/group-event". However, the node add form cannot populate the group audience field by the Entity reference prepopulate module.

SomebodySysop’s picture

Status: Closed (fixed) » Active

The original question was how to automatically fill in the group audience field on a post page. https://drupal.org/files/issues/Screen%20shot%202011-08-09%20at%2010.46....

The original response was to use "hook form alter".

OK, I'd like to use hook_form_alter to select a default group for the group audience field. How do I do that?

I know the form id and I've printed out the form (so I can see all the elements). So, how do I put in default value for just the group audience field, og_group_ref?

Logically, I would think something like this:

function example_form_alter(&$form, &$form_state, $form_id) {
    $form['og_group_ref']['und'][0]['target_id']  = 4; // 4 is the gid of the group I want to automatically select.
}

But, of course, this doesn't work.

Without any guidance on this, or examples, it's incredibly difficult to resolve. I know someone mentioned using prepopulate, but I won't know what group to prepopulate until the form is loaded.

Just a little help, please?

SomebodySysop’s picture

Status: Active » Closed (fixed)
FileSize
183.4 KB
10.97 KB
249.79 KB
127.43 KB

I have the solution. For anyone who has asked this question and was lost about how to go about resolving it, I will step through my process:

1. Download and install the Devel module. https://drupal.org/project/devel This, for me, was the key to resolving this entire issue. You will see why.

2. Next, locate the machine name of the field you wish to modify:

a. One way to do it is to go to Admin->Structure->Content Types->(Your Content Type)->Manage Fields. You will see the machine names of the fields attached to that particular content type. I wanted the Groups audience field, which is og_group_ref. See my attachment "GetFieldNameFromContentType" below.

b. Another way is to go into the Edit screen of an existing node, and use your browser's View Source to view the HTML source of the page. Do a search for the field you are looking for. In my case, I searched for "Groups audience". You can see from my attachment "GroupsAudienceSource" that the field name on this form is "og_group_ref[und][0][default][]".

3. Now, we need to figure out the exact field array configuration for this field on the Drupal form. For this, we use the Devel module. I assume you are either modifying an existing module, or creating your own. So, you will need to put this command in the "hook_form_alter" segment of your module:

function example_form_alter(&$form, &$form_state, $form_id) {
    dpm($form);
}

Save your module with this change. Upload it to your site. In Drupal, edit an existing node which contains the field you wish to provide a default value for. You will now see a form array link at the top of the page. Expand it to see the field names of all the fields on the form on the page. I look for "og_group_ref". See my attachment "Devel_Form_Array_all".

More info on dpm: http://blog.anselmbradford.com/2009/03/14/2-invaluable-drupal-developmen...

4. I now know the field AND it's array structure (which you must have in order to successfully modify it). The following below will set the "Groups audience" field in the edit form to default to group gid "4":

function example_form_alter(&$form, &$form_state, $form_id) {
    $form['og_group_ref']['und'][0]['default']['#default_value'][0] = '4'; // or whatever value you want to put there
}

You will want to be careful about when you actually set this default in your code; I only set it for book pages that are child pages (in order to make sure they are in the same group as their parent).

So, yes, you can automatically fill the group audience field using "hook_form_alter".

Marq’s picture

I wanted to share what I have found in my research.

I'm new to this, but I think this is going to work for me, but may not apply in this situation.

NEW "RULE"

Event = Before Saving New Content --- Node/Content type Action = Data/set data value/node:og-group-ref:0 (Groups Audience)

I use radio boxes with the OG Reference widget. I have only tried with one group per user. (Multiple content types though)