Closed (fixed)
Project:
OG Forum
Version:
5.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
13 Sep 2007 at 14:27 UTC
Updated:
24 Sep 2007 at 16:34 UTC
Hello,
When I log in as non-admin, go to a forum and try to post a new forum, I get the following error:
warning: Invalid argument supplied for foreach() in /home/lala/dev.site.com/sites/all/modules/og_forum/og_forum.module on line 692.
I look on line 692 and this is what I see:
if (!user_access('administer forums') && $cut) {
foreach ($form['taxonomy'][$vid]['#options'] as $key => $the_rest) {
$option_key = key($the_rest->option);
if (array_key_exists($option_key, $all_results)) {
unset($form['taxonomy'][$vid]['#options'][$key]);
}
}
}
Any ideas of what might be causing the error?
Interesting thing is that the error doesn't occur if I post a new forum topic directly without going to a forum.
Thanks,
Andrey.
Comments
Comment #1
rconstantine commentedMaybe this: http://drupal.org/node/169892
You should be using the dev version as clearly stated on the project's page.
Comment #2
mr.andrey commentedUsing dev version now, still the problem persists:
warning: Invalid argument supplied for foreach() in /site.net/sites/all/modules/og_forum/og_forum.module on line 714.Comment #3
rconstantine commentedOkeydokey, let's see what we have here.
Your error indicates that $form['taxonomy'][$vid]['#options'] doesn't exist. This module doesn't originate that array. I'm pretty sure that comes from the basic forum module. So when the function is called, there should be something there. However, if the forum was not setup per the regular forum rules, then it might not. That would mean that somehow you are using the wrong vocabulary for your forums - i.e. one you setup by hand yourself. Which is exactly what I said in that other issue that I linked to previously. So I assume you ignored me and didn't read it.
As nobody else is having this problem, I'm going to assume that's what the problem is. If for some reason it isn't, you can insert this line of code:
drupal_set_message('
');
at the top of the og_forum_form_alter function. If it is empty, then you screwed up your setup. If it has stuff in it, then duplicate the same line after each 'unset' call from the top of the function to the problem code you pasted.
Be sure to change the 'X' to a number and increment it each time you paste so that you can identify where things get messed up.
Comment #4
mr.andrey commentedHello, you're right, I didn't read the post. Now I just did, and I'm still having a difficult time understanding exactly what is happening.
Let me restate the problem here, just to be clear:
When posting a new topic via link "post a new forum topic" from a forum, I get the following errors (different line numbers depending on whether it's in a group forum or not):
> Your error indicates that $form['taxonomy'][$vid]['#options'] doesn't exist.
I just followed your suggestion and in both cases with Admin and non-admin I got no values after "Taxonomy Options X:"
> This module doesn't originate that array. I'm pretty sure that comes from the basic forum module.
I looked in the forum module, and I can't seem to find where $form['taxonomy'] being set. There is $form['vid'], but ['#options'] is not set for it.
My forum module is a standard 5.2 core module.
I did a site-wide grep for $form['taxonomy'] and og_forum is the only module that mentions it.
What exactly does this function do? Everything seems to work when I have the admin forum privileges.
Any ideas?
Comment #5
rconstantine commentedFirst, it is bad that your print statements produce no output, as I suspected.
Second, your grep results surprise me. If you enable a vocabulary for tagging purposes on your forum content type, the selection box for that will appear in $form['taxonomy'], but with a different [$vid] since it is, of course, a different vid.
Let me double check that, but I'm pretty sure.
As I state elsewhere, I think these errors are also related to not setting up the forum module before installing og_forum. The order that should be taken is:
-install forum
-go to admin/content/forum and do what it says (IIRC, there should be a 'create forum' link
-install og_forum
This assumes a clean install of both modules, so you can't just disable/reenable, you would have to uninstall/reinstall and make sure the forum vocab is removed in that process.
At least, I think so. I've been known to be wrong once or twice.
Comment #6
mr.andrey commentedAhh, I have Category module installed, this may be where the problem lies. I just did a grep on my older backups of the site, and it looks like $form['taxonomy'] is set by taxonomy.module, and Category module provides a wrapper for it.
I just did a diff of my version of taxonomy wrapper against the latest one from Category module:
Interesting, that is a patch I applied a while back to fix something with forum compatibility (the "topic has been moved" problem).
Something didn't work with my previous grep results. Here they are again (grep -r "\$form\['taxonomy'\]"
*):
and here are the results from one of my earlier backups (core 5.1, no Category)
It seems like the Category taxonomy wrapper sets a lot less things for $form['taxonomy'].
What do these scripts do in the og_forum module? Everything seems to work besides the error. Can I disable or work around them?
line 699 error:
line 735 error:
Thanks for taking your time helping me with this,
Andrey.
Comment #7
rconstantine commentedThe category module strikes again! Changing this to a support request.
The $form['taxonomy'][$vid] structure can contain any number of things, but what og_forum is concerned about is usually $form['taxonomy][1] which is usually the forum vocabulary and which will contain a listing of then entire forum hierarchy at the start. Og_forum then removes all entries from that list which are outside of the current 'scope' so far as og_forum determines it. What that means is that we remove all forums outside of the current group. If we are at the site-wide forum, then we remove all references to forums to which the user does not have access.
That is what the unset function does.
I see that some of the function is truncated on the right hand side of the first quote you made. I mention that so future readers don't think that those lines actually end with '$'.
So essentially, you need to make sure that somehow, the categories module provides the same functionality as this line:
$form['taxonomy'][$vocabulary->vid] = taxonomy_form($vocabulary->vid, array_keys($default_terms), $vocabulary->help);and those around it. You'll notice in this line a call to the function 'taxonomy_form'. This function in turn calls a couple of other functions which populate the ['#options'] portion of the $form['taxonomy'][$vid]['#options'] structure that og_forum is looking for.Bottom line, category module needs to be made to work with og_forum, in my opinion, and not the other way around since it is the category module which is breaking the basic functionality of Drupal.
So I'm going to mark this issue as closed and advise you to open an issue over there. You have already done a lot of leg work, so I would point them to this thread. Good luck with your project.
Comment #8
rconstantine commented