I'm making heavy changes to the way forums work on my site, and I've currently got it so that adding new forum topics can only be done from inside a (non-container) forum. I need to make the drop-down select box for choosing what forum to post to hidden (only if the user does not have the "administer forums" permission).

But if I set this property $form['taxonomy']['#access'] = 0; the topic will not be assigned to ANY forum. It will show up in the forum you posted to, but with the link saying "This topic has been moved" linking to "forum/0". So far I can't figure out how the taxonomy control works exactly, and why hiding it makes the internal code think it has no selection.

So how can I make the selection box invisible for non-admins without breaking things? I'm sure it's going to be something obvious that I should have figured out.

Comments

rconstantine’s picture

Before you add that line using #access, you need to identify what it removes from the SUBMITTED form. To do this, add something like:

drupal_set_message('<pre>Form values: ' .print_r($form_values, TRUE). '</pre>');

To the submit function. You need to then see how the forum is being assigned, then set that same value before (or do I mean after?) you #access = 0 the feature.

So say that a variable called $form_values['terms']['#value'] is normally set. You would set it yourself with your code, bypassing the user. In other words, I think #access not only removes the form element, but the mechanism for it to be set as well. I could be wrong about that, but try what I've outlined.

devin.gardner’s picture

I've done some more testing, but haven't uncovered much. Even if I set the select box to disabled rather than hiding it, the node won't get associated with the forum correctly. That's right. Even though the select box is going onto the page as always, something in the PHP isn't recognizing it after it gets submitted.

Adding this code here also has no effect at all on the behavior (with or without the line to unset the default_value):

<?php
$form['taxonomy'][$vid]['#value'] = $form['taxonomy'][$vid]['#default_value'];
unset($form['taxonomy'][$vid]['#default_value']);
?>

Note that this same code works as expected if you're applying it to the OG Audiences checkboxes.

When the forum topic node comes back after being submitted, it has a 'taxonomy' member that is set exactly as it should be, but the relationship between the forum and the node is not present in the database.

rconstantine’s picture

Are you still having problems with this? Technically, this support issue is not for the og_forum module, but rather your manipulation of it, which regular software developers would not even think of supporting.

That said, were you using the code snippet from #2 together with that from your original post? If so, you must use the #access thingy BEFORE you set the code in #2. Otherwise you just unset what you set.

If that isn't your problem, I would then think that you need to use #access farther in, i.e. $form['taxonomy'][$vid]['#access'] = 0;. Most particularly because $form['taxonomy'] is used for things other than forums and certain code in the submission of nodes is looking for it for those other purposes. So maybe there is an issue there.

My last guess is that - oh crap, my son came in and distracted me - so I forgot.

rconstantine’s picture

Status: Active » Closed (fixed)

Has been a month with no further input by poster. Closing.

Mark B’s picture

I've done something similar, without the override for admins. Rather than hiding the field or restricting access, I've changed the form field from a select to a value:

/**
 * Implementation of hook_form_alter
 */
function mymodule_form_alter($form_id, &$form) {
  if($form_id == 'forum_node_form') {
    // hide the forum drop-down select box if a forum has been selected already
    if($form['taxonomy'][1]['#default_value'][0]) {
      $form['taxonomy'][1] = array(
        '#type' => 'value',
        '#value' => $form['taxonomy'][1]['#default_value'][0],
      );
    }
  }
}

Should be pretty easy to add a uid check

andrenoronha’s picture

this is pretty nice! thank you!
I assume now that i only have to ommit the field...
but the link "Create Forum topic" of the group menu block becomes invalid, cause it doesnt pass the forum id (i guess)...

andrenoronha’s picture

So is there a way to call the right "create a forum topic" link on the group menu block? I'm using myhookname_og_links_alter...

andrenoronha’s picture

i arranged that...

now, is there a way to hide the forum and audience options?
i'm thinking of a css hack "display: none;"
anybody has a cooler way?

Anonymous’s picture

Although I am having the same problem not with OG Forum but with the standard D6 forum, here is my solution that seems to work and effectively hides the dropdown. Code is in a module. Note that the $vid in my case is "3" and it is hardcoded in the module, which obviously is not good practice.

>
function mymodule_form_alter(&$form, $form_state, $form_id) {
  switch($form_id) {
    case 'forum_node_form':
      $taxonomy = array(
        '#type' => 'hidden',
        '#value' => $form['taxonomy'][3]['#default_value'][0]
      );
      $form['taxonomy'][3] = $taxonomy;
      break;
  }
}
andrenoronha’s picture

thank you
it worked beautifully

what is the $vid?

ofridagan’s picture

can someone please tell me how to do this in drupal 6

andrenoronha’s picture

@ofridagan
the same way
i'm using the 6 version...

SuperContraXTC’s picture

Sorry Guys,

I created a custom mod and tried the example you gave me but the Forums selection box is still there. Please help.

Thanks

andrenoronha’s picture

@SuperContra
post your code here

Ralla’s picture

#9 inspired me to make it safe, so we only hide the forum taxonomy select:

/**
 * Implementation of hook_form_alter().
 */
function module_form_alter(&$form, $form_state, $form_id) {
  switch ($form_id) {
    case 'forum_node_form':
      if (!user_access('administer forums')) { // Insert your own premission here if needed       
        // Hide the forum taxonomy select
        $forum_vid = variable_get('forum_nav_vocabulary', '');
        $taxonomy = array(
          '#type' => 'hidden',
          '#value' => $form['taxonomy'][$forum_vid]['#default_value'][0]
        );
        $form['taxonomy'][$forum_vid] = $taxonomy;        
        
      }
      
    break;
  }
}

Have fun :)

tallsimon’s picture

can i please clarify exactly what this does and where to put it? Does it set the taxonomy term for a forum post to the only term available in the list, or to a predefined default value (i.e. 1 forum)? does it go in the module code or in the theme template.php file?
thank you

andrenoronha’s picture

@tallsimon

it's a hook implementation. it goes in your own module. (create your own folder with TheNameOfYourOwnModule.module and TheNameOfYourOwnModule.info)

function TheNameOfYourOwnModule_form_alter

the value it fills is the forum of the group to which it belongs.