Version 2 of this module was patched to work with Organic Groups. In that thread, it was mentioned that OG compatibility would be added in Version 3, but when you create an image node using plupload, the image does not take on the OG relationship. I did try applying the patch as close as I could and ran update.php, but it still does not appear to work. I am going to attach both patched node_gallery.module and node_gallery.pages.inc to get some feedback. The relevant changes are on line 672 for the module file and 363 for the pages.inc file.

Comments

CoreyMoore’s picture

I am getting this error:

warning: array_merge() [function.array-merge]: Argument #1 is not an array in /var/www/html/sites/all/modules/node_gallery/node_gallery.pages.inc on line 362.

The corresponding line is a part of the patch:

$image_node = (object)(array_merge($form_values['edit_form'], array('gid' => $form_values['gid'])));

I am not a PHP expert, but it appears that PHP 5 causes this bug (because of the way it handles array_merge. I am about to call it a day, but I am going to try and see if I can fiddle with it a bit.

CoreyMoore’s picture

Ok, if I change the syntax of the code to this:

$image_node = (object) array_merge((array)$form_values['edit_form'], array('gid' => $form_values['gid']));

It stops throwing array_merge errors. It still does not apply the gallery group to the image. I'm going to try and attack this tomorrow (maybe looking through the Views Gallery OG integration module may help).

scroogie’s picture

I think you should reverse the patch and start over.

You have to look at node_gallery_nodeapi()

in case 'insert': for the image type you need to do something similar as in the patch, retrieve the organic group of the gallery and set it for the image. Something like

<?
$gallery_node = node_load($node->gid);
$node->og_groups = $gallery_node->og_groups;
$node->og_groups_both = $gallery_node->og_groups_both;
?>

before the drupal_write_record()

In case 'update': you need something similar as in the original patch as well, updating the group of all images in the gallery if the gallery is updated. This would better be done in batch API though.

CoreyMoore’s picture

Ok, adding the code above to the in case 'insert' worked perfectly. However, I am a bit confused about in case 'update.' This is where a node would be updated, correct? I am reading the documentation about batch API right now. Hopefully I can roll out a patch in a couple of hours :)

CoreyMoore’s picture

Ok, this is the code I am trying:

if (module_exists('organic_groups')) {
		  $image = node_gallery_get_types('image', $node, TRUE);
          $node->og_public = $image->og_public;
          $node->og_groups = $image->og_groups;
          $node->og_groups_both = $image->og_groups_both;
		}

I'm not using batch API, although it may be better. The code should update all of the image nodes within the gallery when the gallery is updated, if I understand the 'update' case correctly. It isn't, however, so I am going to continue working on it. I am not sure whether or not I am calling the correct object with 'node_gallery_get_types('images')'.

scroogie’s picture

In case 'update': you need to add after

    elseif (in_array($node->type, (array)node_gallery_get_types('gallery'))) {
         $old_node = node_load($node->nid);

something like (untested)

     if ($node->og_public != $old_node->og_public || $node->og_groups != $old_node->og_groups ||  $node->og_groups_both != $old_node->og_groups_both) {
    $gid = $node->nid;
    $imagenids = node_gallery_get_image_nids($gid, FALSE, FALSE, TRUE);
    $images = array();
    foreach ($imagenids as $imagenid) {
       $images[] = (object)array('nid' => $imagenid, 'og_public' => $node->og_public, 'og_groups' => $node->og_groups, 'og_groups_both' => $node->og_groups_both);
    }
    $operations[] = array('node_gallery_batch_node_save', array($images));

    if (!empty($operations)) {
      $batch = array(
        'operations' => $operations,
        'finished' => 'node_gallery_image_process_finished',
        'title' => t('Processing Gallery Update.'),
        'init_message' => t('Cascading organic group changes to images.'),
        'progress_message' => t('Processing image updates.'),
        'error_message' => t('Encountered an error while updating images.'),
      );

      batch_set($batch);
    }
     }
scroogie’s picture

Title: Organic Groups Compatibility for NG3 » Cascade organic group settings from galleries to images
Status: Active » Needs review
StatusFileSize
new3.84 KB

Perhaps you can try this patch.

scroogie’s picture

CoreyMoore: Could you perhaps review the patch?

CoreyMoore’s picture

Oh, I am very sorry for not checking on this earlier. I didn't apply the patch as written, but I did use the code you suggested, and it worked correctly.

scroogie’s picture

I see. Thank you anyway. Perhaps someone else has an install with OG enabled?

jaapjan’s picture

Patch in #7 works for me! Thanks!

You might also want to add a form_alter on the image node form to hide the group settings there. I did it in a custom form stuff module.

Crom’s picture

I'm looking to integrate NG 3.0-dev into an OG site and am happy to test the patch but after a lot of reading of the issue queue and elsewhere, I have a couple of questions:

I'm looking to allow users to upload personal galleries into their profiles using node_gallery_user_profile. I'd also like group members to be able to upload galleries to groups they are members of. The former would presumably just be posted as 'nodes' and the latter as would presumably be posted as group nodes. so...

1) Should I alter the NG content types to be 'group nodes' or 'standard group posts' or create a new set of NG content types and create a new relationship in the module settings page? Hmmm, I guess that will knacker my plupload integration as it can only be pointed at one field. So, I guess that I can have either group galleries or personal galleries and just use node_gallery_user_profile to display those galleries that users have uploaded to public groups?
2) Is the patch compatible with dev as it looks like it's been written for alpha3

Cheers,
Crom

Crom’s picture

Following some testing and in response to my own questions - in case anyone else wants to try this:

1) I altered the gallery content type to a standard group post and then controlled the access with the OG audience setting for each gallery that is created. This seems to work fine for both group galleries and personal galleries
2) The patch seems to work fine with the current dev version of NG3

foredoc’s picture

Jaapie,

I also need to hide the group settings on the image node form, and tried to unset($form['og_nodeapi']) without success. Could you share with me the way to hide it in hook_form_alter?

Thanks.

foredoc’s picture

seems $form['og_nodeapi']['#access'] = FALSE do the job.

foredoc’s picture

will this patch be included in the next release of NG, say 6.x-3.0-beta3 ?

Thanks.

justintime’s picture

StatusFileSize
new4.71 KB

Attached patch takes #7 and #15 rolled into one. If you can test this patch and mark this as RTBC, I'll get it into beta3.

foredoc’s picture

An error found:

line # 417, line#19(patch file): if (module_exists('og') {

should be : if (module_exists('og') ) {

Thanks.

foredoc’s picture

Status: Fixed » Needs review

Another :

line # 418(node_gallery.module), line#20(patch file): $form['og_nodeapi']['#access'] = FALSE
should be: $form['og_nodeapi']['#access'] = FALSE;

foredoc’s picture

I applied the patch for 6.x-3.0-beta2, after fixing the two lines mentioned above, it works.

Thanks.

justintime’s picture

Status: Needs review » Fixed

Sheesh, that's embarassing. Guess you can tell I did that in a hurry.

I've committed the patch plus your fixes into 6.x-3.x.

foredoc’s picture

Status: Needs review » Fixed

:) Thanks a lot!

Status: Fixed » Closed (fixed)

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