Hi,

[the version of og_galleries.module I'm running is the one you provided me in http://drupal.org/node/108946 ]

og_galleries creates a vocabulary for each group and a term "main". The vocabulary however does not seem to be associated with any node types by default though, which results in no galleries to select when editing my image nodes. I saw that you're trying to assign them via a call to og_galleries_get_types() so I looked into that code.

From what I can tell, the formatting of the node list returned from og_galleries_get_types() may not be what taxonomy_save_vocabulary() is looking for.

This is the code I see in taxonomy_save_vocabulary for a new vocab

foreach ($edit['nodes'] as $type => $selected) {
      db_query("INSERT INTO {vocabulary_node_types} (vid, type) VALUES (%d, '%s')", $edit['vid'], $type);
    } 

But the way og_galleries_get_types() sets up the 'nodes' array is such that the key $type is an integer (the increment) and value $selected is the node type. And save_vocabulary expects the key to be the node type. So it looks like taxonomy_save_vocabulary is inserting a bunch of integers instead of the node names. Does that look right?

Any ways, by intercepting the return to og_galleries_get_types() and building an array with the node type as the key, I think I was able to get it all to work.

  $typelist = og_galleries_get_types();
  $vocabnodes = array();
  	foreach ($typelist as $type => $selected) {
      $vocabnodes[$selected] = $selected;
    } 
  
  $vocabulary = array(
    'name' => $name, 
    'multiple' => '1', 
    'required' => '0', 
    'hierarchy' => '1', 
    'relations' => '0', 
    'module' => 'og_galleries', 
    //'nodes' => og_galleries_get_types(),
    'nodes' => $vocabnodes,
    );

Another thing (perhaps separate). Adding a new group for me is resulting in the following warning:

warning: array_keys() [function.array-keys]: The first argument should be an array in /public_html/drupal/modules/og_galleries/og_galleries.module on line 420.

The code at line 420 is the 1st if statement in the submit block of nodeapi

    case 'submit':
      // Set group permissions to match the selected galleries.
      $og_groups = array();
      if ($tids = (array) array_keys($node->taxonomy) ) {
        $result = db_query("SELECT og.gid FROM {term_data} t INNER JOIN {og_galleries} og ON t.vid = og.vid WHERE t.tid IN (". implode(',', $tids) .")");
        while ($arr = db_fetch_array($result)) {
          if ($arr['gid'] == 0) {
            $og_public = 1;
          }
          $og_groups[] = $arr['gid'];
        }
        $node->og_public = $og_public ? $og_public : $node->og_public;
        $node->og_groups = array_unique(array_merge($og_groups, $node->og_groups));
      }
      break;

thanks,
Patrick

Comments

pcdonohue’s picture

Forget the second part of this issue (the warning error message), I see that you fixed it in your latest release with

$tids = (array) array_keys( (array) $node->taxonomy)

and I see it's not related to the original issue.

...the original issue being that the array returned by og_galleries_get_types doesn't seem to match the format taxonomy_save_vocabulary uses (where the node type is the key, not the value, of the array).

Patrick

karens’s picture

Status: Active » Fixed

Good catch. I fixed it slightly differently, by using:

drupal_map_assoc(og_galleries_get_types())
Anonymous’s picture

Status: Fixed » Closed (fixed)