I have a view with a block and a page. Linking the block to the page the default way with a ... More link ... results to a OG unaware link. And the page is not group aware either.

Is it possible to make a More link into a group aware view? What do I miss?

Comments

moshe weitzman’s picture

Status: Active » Fixed

Technically, you make the View display context aware, not the more link. If you use the Argument 'Organic groups: Groups' you get context set for free. If you use a filter 'Organic groups: Groups' you also get context set for free. See og_views_handler_argument_og_group_nid.inc and og_views_handler_filter_og_group_nid.inc.

Please reopen if needed.

Status: Fixed » Closed (fixed)

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

adam_b’s picture

Version: 6.x-1.1 » 6.x-2.0
Status: Closed (fixed) » Active
StatusFileSize
new9.89 KB

I think I'm having the same issue here. I've used the Argument 'Organic groups: Groups' as suggested, and I've set % in the page URL.

However:
- if I don't use a filter, I get no argument in the page URL
- if I use the filter 'Organic groups: Groups' as suggested, then I get the argument "all"

I've tried this with a couple of different node types, and have run up against the same problem each time. I've attached the exported view definition - any help gratefully received.

clemens.tolboom’s picture

My solution in the end was adding a php value as the more link. With stuff like og_get_context() to build the link myself.

Maybe the problem lies in views module not being able to enrich the more link with context? I dunno :(

Hope this helps a little :(

adam_b’s picture

I think the PHP link should work but I've had problems with it in a similar situation (see #582890). Any chance you could post your PHP code here so I could try it?

I think there's a fundamental bug with the OG Views module when it comes to passing the context - which shouldn't be a problem, since it's just a normal node ID :(

clemens.tolboom’s picture

While trying to find the code I could not remember the exact solution. Trouble was with anonymous users having no og context mixed with this more link. But it is long time ago :(

As in #1 Moshe suggest I think we solved it by adding OG Context for the receiving view.

But that does not solve the anonymous user though.

When needing more help you can try to contact me on IRC ;)

adam_b’s picture

I don't think the problem has been fixed - I'm not employing this for anonymous users, but I'm still not getting the context passed on correctly.

But I fixed my PHP problem thanks - just hadn't turned on the PHP input filter module. Doh!

johnhanley’s picture

I'm experiencing the same kind of contextual problem with Views.

I have a Views page (with a defined path of "node/%/list"), which produces a list of "standard group posts". The view includes a Relationship of "Organic groups: Group node (post)" with "Require this relationship" unchecked. The first (and only) Views argument is "Organic groups: Groups". The page works as expected and displays the desired results, but the group context (when viewing the page as group admin) is lost and the "details" block does not display like the other default pages provided by OG. In other words the "details" block comes and goes depending on the current tab selected.

I've been playing with this for several hours and am stumped. I'm not sure if this is an actual bug or just a configuration problem, but any advice would be greatly appreciated.

ashokc’s picture

Has this issue been resolved? I have a block generated by a view, and the block has a 'more' link enabled. The access to the view is controlled by Group Membership & Members only (via og_views_extra module). All group members are able to see the block, but when they click on 'more' link, they get access denied. In order to debug this, I placed some prints in the file 'og_views_extra.module' and saw that after ' $group = og_get_group_context();' is executed, the value for $group is NULL. Any suggestions? Thanks, I am a newbie.

jvieille’s picture

More generally, the group context is lost when activating a Views.
I tried setting 'Organic groups: Groups' as argument, but this does not help.

jvieille’s picture

Title: No OG context from a views blocks More link. » No OG context from a views

Not only for "Views block more links".

amitaibu’s picture

@jvieille,
Please try using the new argument from #711354: Add a "current group" default argument handler

jvieille’s picture

This did not help.
As soon as the view is activated, the group context is lost.
http://drupal.org/node/711354#comment-2645564

amitaibu’s picture

@jvieille,
What is your View, and where does it appear -- as a block in a group node (where OG can find a context)?

jvieille’s picture

I use OG Vocab that features a block called "Group categories" that shows up when a group is selected, allowing a taxonomy browsing inside the group.
When clicking on a term from this block, it displays in the content area the corresponding nodes for the terms of the current OG group.
The way the nodes are listed does not match my needs (the classical term display in Drupal, offering title, teaser and breadcrump).

To customize the term node list display, I noticed that the default disabled "taxonomy_term" views was called if I enable it.

The problem when using the taxonomy_term View is that group context is lost after hitting a term (it is correctly kept when the Views is disabled)
Applying the argument as indicated on this Views does not change anything.

The code of the OG_Vocal block is the following

function og_vocab_block_view() {
  $group_node = og_get_group_context();
  if ($group_node && node_access('view', $group_node)) {
    foreach ((array)$group_node->og_vocabularies as $vid => $vocab) {

      $tree = taxonomy_get_tree($vid);
      // TODO. link to full page view. maybe views provides this?
      // only show first 20 terms. wary of huge vocabs. not ideal.
      $tree = array_slice($tree, 0, 20);
      $items = og_vocab_build_list_items($index = 0, $tree);
      if ($items) {
        $output .= theme('item_list', $items, $vocab->name);
      }
    }
    $block['content'] = $output;
    $block['subject'] = t('Group categories');
    return $block;
  }
}

Thank you very much for taking care

amitaibu’s picture

Status: Active » Fixed

I think you are mixing something here. The code that is responsible for the group context in og_vocab is:

  // Since this module has to run after taxonomy and before og_menu(),
  // we just set group context.
  $item = menu_get_item();
  if ($item['path'] == 'taxonomy/term/%') {
    // Get the term id from the menu item, and from it get the vocabulary.
    $term = taxonomy_get_term($item['page_arguments'][0]);
    // Check if the vocabulary is assoicated with a group.
    if ($gid = og_vocab_get_group($term->vid)) {
      // Set the group context.
      og_set_group_context(node_load($gid));
    }
  }

This means that is the path isn't exactly taxonomy/term/foo -- then a context won't be set. Maybe the View you enabled changed that path.

jvieille’s picture

The View I am using is the standard (disabled by default) taxonomy_term view
By some magic, it is called by OG_Vocab when I enable it (as this allows me to display change the layout, which is my primary concern)

Its arguments are:

Arguments
Taxonomy: Term ID (with depth)
Taxonomy: Term ID depth modifier

the View path is
taxonomy/term/%

All this seems to match the OG_Vocab block requirements
What can be wrong?

Thanks

jvieille’s picture

No clue?
Why could the coded taxononmy display work with OG Vocab, but not the emulating view (which works for other purposes)

Thanks

jvieille’s picture

I think I am missing something.
I tried to create a view from scratch.
I only succeeded keeping the OG context by submitting explicitly the group node ID as an argument matching the current context, using the argument Organic groups: Groups

Whatever I do, the context is lost as son as the (page) view is displayed.
I tried the diffferent arguments and filters, with and without default settings as suggested, nothing works.

Status: Fixed » Closed (fixed)

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

jvieille’s picture

Status: Closed (fixed) » Active

+1 - this is no way solved
I really have no idea what to do.
This might be specific to OG Vocab as the View is called by the OG Vocab block.

nbluto’s picture

Status: Active » Closed (fixed)

Thank you Moshe, this worked for me. I passed an argument to my target view (where my "more" link points to) that is group-group with a default argument of Node ID from URL and a validator as basic.

The Block display is also set with an argument of group-group with a default argument of NID from URL with a validator of Group Nodes and argument type NID with Action to take if argument does not validate as Display all values.

This works. I have my block view and when I click on the more link, I can see my page view and it passes the NID and stays in group context with all blocks displaying that belong to the group.

Thanks.

jvieille’s picture

I found a solution in the case of OG Vocab Group Category block
http://drupal.org/node/763308

Still the issue seems not solved for me because it seems that the context can only be captured and kept by a view if the group nid is in the url that calls the view.
Any OG group "default argument" setting is ineffective without this primary condition, while almost any setting works when the url explicitly hods the group node id.

Rosamunda’s picture

Status: Closed (fixed) » Active

I´ve got a block that I want it to be shown inside each group, or group page.
It works, but not when the viewed page is created by a view (it does work in node view/edit pages).

I´m using this code inside "Show if the PHP code is true":

<?php
  $in_og = FALSE;
if (module_exists('og')) {
  $in_og = TRUE;
  $group_node = og_get_group_context();
  $gid02 = $group_node->nid;
  $gid = (int)$gid02;
  if ($gid02 === null) $gid = 0;
  if ($gid == 0) $in_og = FALSE;
}
return $in_og;
?>

The page created by views is og/polls/%.

I just don´t know why this code doesn´t work with pages created by views that got the context actually...

Inside my view, I´ve got:

Arguments:
Provide default argument
Provide default argument options: Node ID from URL
Validator options: Group nodes / Node ID

Any ideas?
Thanks!!

Rosamunda

maarudth’s picture

i found a solution to the situation where a page created by a view loses context.
in my case the context was not totaly lost - just the theme...

solution:
in og.module
line 565:
function og_determine_context() {
at the end of the if, eleif
chain added
else{
$node = node_load(arg(1));
}

that solved it for me.

anyone with more expirience in these matters - please confirm or condem this solution...

protoplasm’s picture

I've tried og relationships, arguments, and filters to solve this problem, but context does not seem to be passed. Also #25 did not work as well.

I don't think it is just a taxonomy term issue. I've tried using search as well and the page generated from either an exposed block page or a regular block in the context of a group only pulls the wildcard 'all' or '*' and gives nothing group specific. I even tried using a fixed entry with the group id as the argument. Still no luck. I've just started to look into this issue to develop a new feature so if anyone has found a solution, it would be very helpful.

Thanks.

protoplasm’s picture

Apparently, the solution is related to the path of the page. In my case, I had to use % like this
http://xxxxx.com/xxxxxx/%/content/xxxxxxx along with an organic groups argument and relationship. Everything has to be just right or it doesn't work. Got this to finally work with both taxonomy and search.

pelicani’s picture

Version: 6.x-2.0 » 6.x-2.1
Component: Og Views » og.module

#25 worked
our views are now displaying in the correct og context.
we pass an argument as a group - group and it is rendered in the group theme

but I'm confused...
did I build my view wrong so I need this hack?
or
can we put the modification committed to og.module?

peace,
michael

jvieille’s picture

As I put in #23, there is no way for Views - as it is currently - to get context "automagically".
Any default argument setting does not work, the only way is to explicitly pass the group in the argument.

If #25 allows this (calling a view from a group context without passing the group in argument and not leaving this context), this is a great, welcome feature. I have no chance to test this right now, but I am still interested.

Grayside’s picture

Category: support » bug

This issue could use a patch with a test, or at least a testing summary.

maarudth’s picture

i think the only reason the solution in #25 would not work is if the nid in the page url is not arg -1.
the solution would be to look for the numeric arg...

jody lynn’s picture

The hack in #25 is not at all recommended. This could incorrectly set a group context on a non node page. For example if you visit /user/6 it will set the group context for that user to that of node 6.

The problem is that it's too late to set the group context within the views argument handler with respect to setting a custom theme. I'm using a custom hook_init implementation like:


function FOO_init() {
  if (arg(0) == 'foopath' && is_numeric(arg(1))) {
    global $custom_theme;
    $og_group = node_load(arg(1));
    if ($og_group->og_theme) {
      $custom_theme = $og_group->og_theme;
    }
  }
}

where I have a view at /foopath/% with an og argument.

lirantal’s picture

Assigned: Unassigned » lirantal
Status: Active » Needs work
StatusFileSize
new713 bytes

Please see this patch which adds another method of detecting group context based on the url, much like prior attempts in the function call and there's no risk of loading a different group as mentioned by Jody since it uses since the loaded node is passed to og_determine_context_get_group() which checks this is indeed a group node type.

lirantal’s picture

StatusFileSize
new634 bytes

Actually, here's a fix to the former patch which is a safer method of just getting correctly the url segment.

lirantal’s picture

StatusFileSize
new634 bytes

Ugh, and now with a version that is actually viewable via drupal (no idea why no url encoding is taking place here for links...)

Grayside’s picture

Title: No OG context from a views » Getting OG context for views
antarchi’s picture

#27 worked for me, THANKS protoplasm!

soulfroys’s picture

#1 worked for me! Thanks @Moshe!

Grayside’s picture

Issue tags: +Context

@#35, The menu_get_object() function will include the node object if it is set via the path.

Working on the logic in

elseif ((!empty($item['map'][2]) && $item['map'][0] == 'og') || $path == 'comment/reply/%') {
  $node = menu_get_object('node', 2);
}

should help expand it's usage to cover the case you are trying for.

lahode’s picture

Hi,

I'm not sure it's the purpose of this thread, but for info, I found a completely other way to have the group argument retrieved

I added to the view 2 relationships:

  • OG membership: OG membership from Node
  • (OG membership from node) OG membership: OG group gid (depending on the previous relation)

Then I added a "(OG group) OG group: Entity id" contextual filted and using the simple module http://drupal.org/project/views_arg_context, I configured "Provide default value: Type->Active Context / Namespace -> node / Attribute -> nid"

Finally I created a standard context on my group and that's all.

Hope it helps somebody

jvieille’s picture

1) What do you mean by a "standard context "
2) I don't find "OG membership: OG membership from Node" nor "OG membership: OG group gid", only
"Organic groups: Group node (member)" and "Organic groups: Group node (post)"

Please clarify.

Thanks

lahode’s picture

Sorry, I happened to see only now that it was a D6 post... ok forget about, my solution is for D7

wcDogg’s picture

I’m trying to solve this same issue. I know nothing about code. Looking around in the “native” OG Views, I tried stealing the argument in og_files. I’m part of the way there, but need a little more help. Here’s what I’ve got so far …

Default View > Arguments > Organic Groups: Groups

  • Action if not present = PHP Code – see code below (don't copy/paste the opening and closing tags)
  • Validator = Group nodes
  • Argument Type = Node ID
  • Membership Validation = Do not validate
  • Action if does not validate = 404
if ($node = og_get_group_context()) {
                return $node->nid;
              }
              else {
                return NULL;
              }

Default View > Filters

  • Node Published = Yes
  • Node Type = Applicable Content Type
  • Organic Groups: Posts in current group

Block View > More Link = Yes (silly, but I note everything)

Page View > Path = group/%

This gives me a working More link – the Page View returns a list of nodes for the correct Group.

Since I’m no coder, I have no idea why this works – only that I felt safe using the PHP because it came with OG.

Some things I’m wondering about that may or may not belong here, but would appreciate knowing:

  1. For Page > Path, am I correct that the % is calling the argument, and if there had been more than one, I would use %1, %2, etc.?
  2. For Page > Path, I’d like to use a replacement value to grab the Group’s name. My guess is another argument, but I don’t know which one.
  3. The resulting page only shows “Home > My Unread” (/traker) in the breadcrumb. I’d like users to see the Group node they came from instead of "My Unread". I see the argument provides a breadcrumb option, but I have no clue if this is what I’m looking for or how to use it.

If you’re kind enough to answer any of these, for the love of Pete, please be specific because I’m slow on the uptake :)

Thanks in advance - Lisa

claudiu.cristea’s picture

Issue summary: View changes
Status: Needs work » Closed (outdated)

This version of Drupal is not supported anymore. If this is still an issue in the 8.x-1.x branch, please open a new up-to-date ticket. Closing.