--- a/sites/all/modules/og/og_context/og_context.module +++ b/sites/all/modules/og/og_context/og_context.module @@ -124,6 +124,13 @@ 'menu path' => array('node/%', 'group/%/%/admin'), ); + $providers['file-upload'] = array( + 'name' => t('File upload'), + 'description' => t("Determine context by checking the user's session during file uploads."), + 'callback' => 'og_context_handler_file_upload', + 'menu path' => array('file/ajax'), + ); + $providers['user-view'] = array( 'name' => t('User view'), 'description' => t("Determine context by checking if a user is a group or a group content on the 'user view' page."), @@ -332,8 +339,8 @@ * The group ID for the current context. */ function og_context_determine_context($group_type, $item = NULL) { - // Enable url and node context handlers by default. - $defaults = array('url' => -5, 'node' => -4); + // Enable url, node, and file-upload context handlers by default. + $defaults = array('url' => -5, 'node' => -4, 'file-upload' => -3); if (!$enabled_providers = array_keys(variable_get("og_context_negotiation_group_context", $defaults))) { return; } @@ -490,6 +497,26 @@ } /** + * Context handler; For file upload, get context from session. + */ +function og_context_handler_file_upload() { + $item = menu_get_item(); + + if (strpos($item['path'], 'file/ajax') !== 0) { + return; + } + + // For file uploads, use the group in the $_SESSION. + // This means that when performing a file upload, there will be a valid + // group context when the form is being rebuilt. + $gids = array(); + if (!empty($_SESSION['og_context']['group_type'])) { + $gids = array($_SESSION['og_context']['group_type'] => array($_SESSION['og_context']['gid'])); + } + return $gids; +} + +/** * Context handler; Get groups from user view. */ function og_context_handler_user_view() {