Hello,

I've noticed that there's a problem with the taxonomy wrapper module that affects og_forum (and possibly other) modules.

We tried to find a solution with the og_forum developer, rconstantine, but it seems like it lays in the code of the Category taxonomy wrapper.

Here is the link to our findings: http://drupal.org/node/175364

On the outside the problem looks like this:

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):

warning: Invalid argument supplied for foreach() in /home/.puppy/fredburks/portal.transformationteam.net/sites/all/modules/og_forum/og_forum.module on line 679.
warning: Invalid argument supplied for foreach() in /home/.puppy/fredburks/portal.transformationteam.net/sites/all/modules/og_forum/og_forum.module on line 715.

It seems that in the core it is because the taxonomy_form_alter function in the wrapper doesn't populate $form['taxonomy'][$vocabulary->vid]. I compared the wrapper with the original version, and the wrapper version is significantly shorter. Below are the two functions.

Category's taxonomy wrapper:

function taxonomy_form_alter($form_id, &$form) {
drupal_set_message('Taxonomy Options Y: '.$node->taxonomy .print_r($form['taxonomy'][$vid]['#options'], TRUE). '');
  if (!isset($form['type']) || $form['type']['#value'] .'_node_form' != $form_id) {
    return;
  }

  $edit = $_POST['edit'];

  $form['taxonomy'] = array(
    '#type' => 'value',
    '#value' => $edit['category'],
  );
}

Original taxonomy module:

function taxonomy_form_alter($form_id, &$form) {
  if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id) {
    $node = $form['#node'];

    if (!isset($node->taxonomy)) {
      if ($node->nid) {
        $terms = taxonomy_node_get_terms($node->nid);
      }
      else {
        $terms = array();
      }
    }
    else {
      $terms = $node->taxonomy;
    }

    $c = db_query(db_rewrite_sql("SELECT v.* FROM {vocabulary} v INNER JOIN {vocabulary_node_types} n ON v.vid = n.vid WHERE n.type = '%s' ORDER BY v.weight, v.name", 'v', 'vid'), $node->type);

    while ($vocabulary = db_fetch_object($c)) {
      if ($vocabulary->tags) {
        $typed_terms = array();
        foreach ($terms as $term) {
          // Extract terms belonging to the vocabulary in question.
          if ($term->vid == $vocabulary->vid) {

            // Commas and quotes in terms are special cases, so encode 'em.
            if (strpos($term->name, ',') !== FALSE || strpos($term->name, '"') !== FALSE) {
              $term->name = '"'.str_replace('"', '""', $term->name).'"';
            }
            $typed_terms[] = $term->name;
          }
        }
        $typed_string = implode(', ', $typed_terms) . (array_key_exists('tags', $terms) ? $terms['tags'][$vocabulary->vid] : NULL);

        if ($vocabulary->help) {
          $help = $vocabulary->help;
        }
        else {
          $help = t('A comma-separated list of terms describing this content. Example: funny, bungee jumping, "Company, Inc.".');
        }
        $form['taxonomy']['tags'][$vocabulary->vid] = array('#type' => 'textfield',
          '#title' => $vocabulary->name,
          '#description' => $help,
          '#required' => $vocabulary->required,
          '#default_value' => $typed_string,
          '#autocomplete_path' => 'taxonomy/autocomplete/'. $vocabulary->vid,
          '#weight' => $vocabulary->weight,
          '#maxlength' => 255,
        );
      }
      else {
        // Extract terms belonging to the vocabulary in question.
        $default_terms = array();
        foreach ($terms as $term) {
          if ($term->vid == $vocabulary->vid) {
            $default_terms[$term->tid] = $term;
          }
        }
        $form['taxonomy'][$vocabulary->vid] = taxonomy_form($vocabulary->vid, array_keys($default_terms), $vocabulary->help);
        $form['taxonomy'][$vocabulary->vid]['#weight'] = $vocabulary->weight;
        $form['taxonomy'][$vocabulary->vid]['#required'] = $vocabulary->required;
      }
    }
    if (is_array($form['taxonomy']) && !empty($form['taxonomy'])) {
      if (count($form['taxonomy']) > 1) { // Add fieldset only if form has more than
1 element.
        $form['taxonomy'] += array(
          '#type' => 'fieldset',
          '#title' => t('Categories'),
          '#collapsible' => TRUE,
          '#collapsed' => FALSE,
        );
      }
      $form['taxonomy']['#weight'] = -3;
      $form['taxonomy']['#tree'] = TRUE;
    }
  }
}

$form['taxonomy'][$vocabulary->vid] is used by og_forum to get 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.

Is there a way to re-enable this functionality in the wrapper module?

Thanks,
Andrey.

Comments

sugardave’s picture

Subscribing.