diff --git a/og_context/includes/views/og_context_plugin_access_og_perm.inc b/og_context/includes/views/og_context_plugin_access_og_perm.inc index d4050c4..d1b208a 100644 --- a/og_context/includes/views/og_context_plugin_access_og_perm.inc +++ b/og_context/includes/views/og_context_plugin_access_og_perm.inc @@ -16,13 +16,17 @@ class og_context_plugin_access_og_perm extends views_plugin_access { function access($account) { // Attempt to get the group from the current context and determine if the // user has the appropriate permission within the group - $group = og_context(); - if (!$group) { - // We should not allow access to the view if we were unable to find a - // group - return FALSE; + if ($group = og_context()) { + return og_user_access($group->gid, $this->options['perm'], $account); } - return og_user_access($group->gid, $this->options['perm'], $account); + return FALSE; + } + + /** + * Determine the access callback and arguments. + */ + function get_access_callback() { + return array('_og_context_views_page_access', array($this->options['group_type'], $this->options['perm'], $this->options['entity_id_arg'])); } /** @@ -40,6 +44,8 @@ class og_context_plugin_access_og_perm extends views_plugin_access { function option_definition() { $options = parent::option_definition(); $options['perm'] = array('default' => 'edit group'); + $options['group_type'] = array('default' => 'node'); + $options['entity_id_arg'] = array('default' => ''); return $options; } @@ -63,5 +69,20 @@ class og_context_plugin_access_og_perm extends views_plugin_access { '#default_value' => $this->options['perm'], '#description' => t('Only users with the selected permission flag in a group retrieved from context will be able to access this display.') ); + // TODO: add Group to this list so people can use the gid instead of eid. + $form['group_type'] = array( + '#type' => 'select', + '#options' => og_get_all_group_entity(), + '#title' => t('Group type'), + '#default_value' => $this->options['group_type'], + '#description' => t('Determine what entity type that group should be of.') + ); + $form['entity_id_arg'] = array( + '#type' => 'textfield', + '#title' => t('argument position for group ID'), + '#size' => 1, + '#default_value' => $this->options['group_id_arg'], + '#description' => t('Entity ID (Entity forming the group you want) position accessed with the arg() function. e.g If your dynamic path is "node/%/overview" to choose "2" like "arg(2)".'), + ); } } diff --git a/og_context/og_context.module b/og_context/og_context.module index 6c8a83a..4dbc3d7 100644 --- a/og_context/og_context.module +++ b/og_context/og_context.module @@ -568,3 +568,27 @@ function _group_context_handler_entity($entity_type = 'node', $entity = NULL, $p return $context; } + +/** + * Helper function to handle views page access. + * + * @param $group_type + * The group type. + * @param $perm + * The group permission to search for. + * @param $entity_id_arg + * Optional; The position in arg() where the group's entity ID can be found. + */ +function _og_context_views_page_access($entity_type = 'node', $perm = NULL, $entity_id_arg = '') { + if ($entity_id_arg != '' && is_numeric($entity_id_arg)) { + $eid = arg($entity_id_arg); + if (is_numeric($eid)) { + $entities = entity_load($entity_type, array($eid)); + if (empty($entities)) { + return FALSE; + } + return og_user_access_entity($perm, $entity_type, array_shift($entities)); + } + } + return FALSE; +}