The Following error comes whenever i am trying to post a new question in the group

Notice: Undefined index: und in commons_q_a_views_pre_render() (line 93 of /var/www/profiles/commons/modules/contrib/commons_q_a/commons_q_a.module).
Warning: Invalid argument supplied for foreach() in commons_q_a_views_pre_render() (line 93 of /var/www/profiles/commons/modules/contrib/commons_q_a/commons_q_a.module).

I have also attached a screen shot of the error page please help me with some solution as soon as possible...


ezra-g’s picture

Status:Active» Postponed (maintainer needs more info)

Can you share the error you're receiving? It's difficult to help you without knowing what the problem is.

Rafiq Jewale’s picture

Assigned:Unassigned» Rafiq Jewale
new215.24 KB
japerry’s picture

Status:Postponed (maintainer needs more info)» Active

This can be reproduced by going to node/add/question without an og_node_ref at the end. By taking off the argument for the group, and not adding a group in the reference, it will cause this problem.

We should add a sanity check just in case, but also make the group field required for questions. This error only occurs if the group reference field is empty.

japerry’s picture

Assigned:Rafiq Jewale» japerry
japerry’s picture

Version:7.x-3.0» 7.x-3.1
Priority:Normal» Major
Status:Active» Reviewed & tested by the community
new3.58 KB

here is a re-write of that snippet of code.. what it changes:

1) requires that user have access to post answers in general for the answers page to show up
2) not only associates an answer with a question, but to the group the question belongs to as well. It also checks user access to only post the answer to groups which the user has access to.
3) Does a check to make sure if the group field is empty to not throw the error, which is the basis of this bug.
4) still allows a user to post an answer, even if they are not assigned to a group. As long as the user has global permission to post answers.

ezra-g’s picture

Status:Reviewed & tested by the community» Needs review

I think this is the correct status :).

japerry’s picture

lol what!? heh thats funny, it was late on friday ;-)

ezra-g’s picture

Status:Needs review» Needs work

I believe this needs work:

Per a comment in Commons_Groups module, the code flow for node access with OG is:


Therefore, starting with a call to node_access() without specifying a group might deny a user the ability to create questions when she lacks permission to do so sitewide, but has permission to do so within specific groups.

So, I think we can use a single call such as

if (og_user_access('node', $value['target_id'], 'create answer content')) {

once, and show the form if the user has access to post into any of the target groups.

I believe that even with entityreference prepopulate, OG's form validation handlers will still prevent the user from posting into groups where she lacks access.

japerry’s picture

new4.03 KB

This should do a better check of node access permissions, and tested to work with anonymous and og_user_access for certain groups.

ezra-g’s picture

Status:Needs work» Needs review
ezra-g’s picture

Looks better!
2 questions about the below code:

+    $answer_access = FALSE;
+    if (!empty($question->og_group_ref[LANGUAGE_NONE])) {
+      foreach ($question->og_group_ref[LANGUAGE_NONE] as $key => $value) {
+        // Check to see the user has access to the group the question is in, only attach to those groups they have permission to post in.
+        if (og_user_access('node', $value['target_id'], 'create answer content')) {
+          $group_ref[] = $value['target_id'];
+          $answer_access = TRUE;
+        }
+      }
+    }
+    // If user belongs to no groups, or no groups are assigned to the Question, check node_access for user.
+    if (!$answer_access) {
+      if (node_access('create', $question, $user)) {
+        $answer_access = TRUE;
+      }
+    }
+    // Check global user access before showing the answer form.
+    if ($answer_access) {

IMO it would be significantly easier to follow this code if we did an if/else, instead of the if, then if (!$answer_access) followed by if($answer_access).

A code comment reads:

Check global user access before showing the answer form.

I think maybe this used to refer to the global $user that's at the top of the function and probably intends to read something like, "If the user doesn't have permission to create an answer, don't display the answer creation form."

Also, I received the error, "fatal: git diff header lacks filename information when removing 1 leading pathname components (line 5)" when trying to apply the above patches via git apply. patch -p1 work, but only after specifying the target filename.

ezra-g’s picture

Status:Needs review» Needs work
japerry’s picture

Status:Needs work» Needs review
new4.01 KB
japerry’s picture

Status:Needs review» Fixed
Issue tags:+Commons 7.x-3.2 radar

Fixed from comments above, and patch is now using p1.. althiough that doesn't really matter once its committed ;-)

Commit here:

Status:Fixed» Closed (fixed)

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

Honestly Illustrated’s picture

Title:Getting error while posting new questions..» Getting error while posting new questions or answers
Version:7.x-3.1» 7.x-3.2
Category:support» bug
Status:Closed (fixed)» Active

On 7.x-3.2, I'm getting the same error in a different line of the same module:

Notice: Undefined index: und in commons_q_a_field_attach_submit() (line 192 of /var/www/profiles/commons/modules/contrib/commons_q_a/commons_q_a.module).

This happens any time I post an Answer reply to a Question: when done on the question node page, and through /node/add.

I was also (on the same pages and action) getting the Warning and Notice errors from #1887246: Adding content with no group generates array errors which its #8 patch solved. That patch won't pass diff --git with 7.x-3.2 as-is, but the minor change it makes can be made and does fix this instance of that bug.

Devin Carlson’s picture

Title:Getting error while posting new questions or answers» Getting error while posting new questions..
Version:7.x-3.2» 7.x-3.1
Category:bug» support
Status:Active» Closed (fixed)

Please file new issues for any problems you come across instead of hijacking and reopening existing issues.

Your issue with error notices being generated while posting questions is answers is covered by #2008930: OG reference occurs to be a bug gap if isn't set.

Honestly Illustrated’s picture

Pardon me sir, but I am not hijacking.

Do you not want people to research our problems before we bother you?

It's the same error merely on a different line. Thank you for your help, but please do not insult.

Edit: Also, I was taking cue from #1887246: Adding content with no group generates array errors where ezra-g asked for that issue to be reopened if seen again.

- $entity->og_group_ref[LANGUAGE_NONE] = $question->og_group_ref[LANGUAGE_NONE];
+ $entity->og_group_ref = $question->og_group_ref;

On .../commons_q_a.module does solve my occurrence of the error in 7.x-3.2

Honestly Illustrated’s picture

Issue summary:View changes

Added the error page screen shot