diff --git a/og_context/og_context.module b/og_context/og_context.module index dd28bd5..e7e4ceb 100644 --- a/og_context/og_context.module +++ b/og_context/og_context.module @@ -123,6 +123,13 @@ function og_context_og_context_negotiation_info() { 'callback' => 'og_context_handler_node', 'menu path' => array('node/%', 'group/%/%/admin'), ); + + $providers['file-upload'] = array( + 'name' => t('File upload'), + 'description' => t("Determine context by checking the form's action parameters during file uploads."), + 'callback' => 'og_context_handler_file_upload', + 'menu path' => array('file/ajax'), + ); $providers['user-view'] = array( 'name' => t('User view'), @@ -332,8 +339,8 @@ function og_context_provider_weight($provider) { * 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 = variable_get('og_context_negotiation_group_context', $defaults)) { return; } @@ -490,6 +497,36 @@ function og_context_handler_node($node = NULL) { } /** + * Context handler; For file upload, get context from form's action.. + */ +function og_context_handler_file_upload() { + $item = menu_get_item(); + + if (strpos($item['path'], 'file/ajax') !== 0) { + return; + } + + // For file uploads, use the group based on the form's #action. + // This means that when performing a file upload, there will be a valid + // group context when the form is being rebuilt. + $gids = array(); + list($form, $form_state) = ajax_get_form(); + + if (preg_match("/og_group_ref=(\d+)/", $form['#action'], $matches)) { + if (isset($matches[1])) { + $group_id = $matches[1]; + if (preg_match("/destination=([\w_\-]+)/", $form['#action'], $matches)) { + $group_type = $matches[1]; + if (og_is_group($group_type, $group_id)) { + $contexts[$group_type][] = $group_id; + return $contexts; + } + } + } + } +} + +/** * Context handler; Get groups from user view. */ function og_context_handler_user_view() {