Is it possible to do this : Create a link in a group's home page that links to a view, which only shows content from that group/subgroup.

Doesn't sound that hard? but....

I tried this by putting a link at the bottom of a group page "click here." I then created a view using the filter "OG: Posts in current group", but when the view is displayed it exits the group and the filter does not work and nothing is shown in the view. I know the exit has occured because the group menu disappears.

So, is there a way of passing a group ID to the view?

I can create content in a group via a link by using /node/ognodeadd?type=tutorial&gids[]=5 (i copied this from the address created by the group menu)
In the address there is ognodeadd (og-node-add) which i assume tells drupal to create the content in that group, can you do a similar thing for just viewing content? Something like ognode/nodetitle?

or is there an easier solution to this?

Comments

SomebodySysop’s picture

I tried this by putting a link at the bottom of a group page "click here." I then created a view using the filter "OG: Posts in current group", but when the view is displayed it exits the group and the filter does not work and nothing is shown in the view. I know the exit has occured because the group menu disappears.

You have to preface the view url with "og", as in: "og/yourview/yourgroupID".
Here is an export of a view I created that lists just "page" content type nodes from a particuluar group:

  $view = new stdClass();
  $view->name = 'OGPages';
  $view->description = '';
  $view->access = array (
);
  $view->view_args_php = '';
  $view->page = TRUE;
  $view->page_title = '';
  $view->page_header = '';
  $view->page_header_format = '3';
  $view->page_footer = '';
  $view->page_footer_format = '3';
  $view->page_empty = '';
  $view->page_empty_format = '3';
  $view->page_type = 'table';
  $view->url = 'og/ogpages';
  $view->use_pager = FALSE;
  $view->nodes_per_page = '0';
  $view->sort = array (
  );
  $view->argument = array (
    array (
      'type' => 'gid',
      'argdefault' => '1',
      'title' => '%1',
      'options' => '',
      'wildcard' => '',
      'wildcard_substitution' => '',
    ),
  );
  $view->field = array (
    array (
      'tablename' => 'node',
      'field' => 'title',
      'label' => 'Title',
      'handler' => 'views_handler_field_nodelink',
      'sortable' => '1',
      'options' => 'link',
    ),
    array (
      'tablename' => 'node',
      'field' => 'changed',
      'label' => 'Updated',
      'handler' => 'views_handler_field_date_small',
      'sortable' => '1',
      'defaultsort' => 'DESC',
    ),
  );
  $view->filter = array (
    array (
      'tablename' => 'node',
      'field' => 'type',
      'operator' => 'OR',
      'options' => '',
      'value' => array (
  0 => 'webform',
  1 => 'page',
),
    ),
  );
  $view->exposed_filter = array (
  );
  $view->requires = array(node);
  $views[$view->name] = $view;

A link to "og/ogpages/(GroupID)" will list all "page" nodes in the Group with ID number GroupID.

najibx’s picture

Hi,
I wanted to use different theme for each group. How can I pass the argument "built-in" in the theme, page.tpl.php or node.tpl.php or template.php or node-group.tpl.php?

I don't want to Views/Panels2 in the URL to carry out the argument.

Actually, I prefer to use Panel2 instead of just Views. So far I still cannot set the panel at OG homepage after following a few suggestion in the forum. Need help there too.

thanks

ldway’s picture

YOU SAID: "A link to "og/ogpages/(GroupID)" will list all "page" nodes in the Group with ID number GroupID."

ok... For me I have created views built for doing the same. However, These views are meant to be generic for usage in each and every group. For example listing pages or story content created only for the current group.

Now, how in the world does one create a link on a group home page that will pass whatever the current group ID is to the view?

For example... I simply want to create a menu that will display in all groups that will have:

"List pages"
"List Stories"

I then need to have the menu automatically created for the current group the person is viewing and the menu links need to call the view setup for each and only against the current group the user is viewing, So somehow there must be a way to build the links dynamically and pass the current group to the view.

I have my views filtered for current group. However, simply calling a view with a standard link takes the person away from the group home page (All the create menu links are gone). I want the person to stay in the group when viewing a view I created.

How does everyone accomplish this?

moshe weitzman’s picture

You have to write some custom code for those links. Your code will call og_get_group_context() to get a $group_node object and that contains the $group_node->nid integer which you will in the link in order to get to the right page.

ldway’s picture

Thanks for overview Moshe...

Finally got it all figured out and working. Thanks again for pointing me the right direction!

--Dave

henns20’s picture

sorry i don't want to take this conversation backwords but i am confused...

it seems like this thread speaks to the issue that i submitted http://drupal.org/node/200375.

couple of questions- i guess there is no solution to use views (form/interface) to try to get a page view of a block (i am using panels for a homepage on og)....you would need custom code for it sounds like.....

moshe or dnosker is there any way you can provide a snippet on this? i am not to sure how to do it---or if you can point me to something similar so i can get an idea of how it is formed. ..

moshe i noticed you lived in philly for a while - can you help a philly brother out:) (saw your post in philly drupal grps).....thanks again ---jamie

gracearoha’s picture

Dave,

I have also been trying to figure out how to create this same type of link.
Could you share the code that you used, please?

j_orbin’s picture

I would also be interested in this code...

Thanks-
Jim

ldway’s picture

Ok, I will do my best to explain exactly what I did, I will take you step-by-step and try to leave nothing out. Pardon for the length of this!...

First you need to understand my use case which may be different than what you are trying to do... In my case, I wanted the following:

1... Have some views that ALL groups will want to use for content that is specific to each group. In other words, while the content created may be specific and viewable only in each group, the contents types available are all the same. i.e. stories, audio, or a page, etc..

2... Based off of the above, I want the same menu for all the views to be on each group page.

3... When a user clicks on a views link in a menu, only the posts for that content type and group are visible.

4.. And finally, when in the view, the user is still in the group without losing all the normal menu's and such of the original group.

So, here is my recipe and steps for all this. Perhaps this all can be done differently but this works for my use case...

-------------------------
1... Creating the Views:
-------------------------
In order for all this to work correctly and have the view stay within the group without leaving the group and original group menu's, etc. you must make your views special for og.

(A) Make a view for each content type you will be supporting in all groups. For this example I will make a view for story content:

... For the View Name Field call it "OGStories"

... Check the box "Provide Page View"

... For the URL field make it "og/ogstories" (IMPORTANT, you must start the url out with "og" or this will not keep you in the group when the view is run!

... For my example view type is "Table View"
... "Title" anything you like. "Story Listing"
... "Use Pager" is checked
... "Breadcrumb Trail should not include home" checked. This is because the home link will be your home page and not the og page if the user clicks it!
... "Nodes Per Page" whatever you want. Mine is at 30.
... under the "Empty Text" field "There are no Stories in this group"

FIELDS:
... Create your fields. I have Title as link, Node Created Time, Node updated time.

ARGUMENTS:
... Add Argument of "OG: Group Nid(s), Set the default to "Page Not Found" put in the title field "%1"

FILTERS:
... Add a filter for "Node: Type". Operator set to "Is One Of" and the value "Story".
... Add a filter for "OG: Posts in current group" Operator set to "Is Equal To" and value "Current Group"

SAVE THE VIEW.

-------------------------
2... MAKING THE MENU TO CALL THE VIEW IN EACH GROUP
-------------------------

... Make a new block.
... In the block description put something like "Group Content"
... Put the same thing in Block Title.
... In the Block Body you will put the following php code. Make sure that you set the Input Format for the Block Body to "PHP Code"

PHP CODE:

if (module_exists('og')) {
  $group_node = og_get_group_context();
  $gid02 = $group_node->nid;
  $gid = (int)$gid02;
  if ($gid02 === null) $gid = 0;
  $output .= "<div class=\"item-list\">
<li><a title=\"Listing of Stories\" href=\"http://YOUR_SITE.COM/og/ogstories/$gid\">Stories</a></li>
</div>";
print $output;
}

-------------------------------------
NOTES:

... You can add other items to this block by following the same format as above (from the li to the end /li Then just set the correct names and views for each item.

... If your wondering why I check for the module og to exist: This is because if you do not do this and later want to disable og (For upgrading, etc) you will have a very big problem. The php code you put into this block will try and run anyways even though og is not enabled and the function "og_get_group_context()" will return a big error for you on your site. (In my case a blank white screen with no way back into the site unless I hand reset og back to being enabled in mysql.)

Block Page specific visibility settings:
You need to provide this to force your menu block to only display on the OG pages and not on the rest of your site.

... Click the radio button "Show if the following PHP code returns TRUE (PHP-mode, experts only)."
... Enter the following code in the Pages: box...

PHP CODE:

  $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; 

----------------------------------------

ENABLE THE BLOCK!

That should do it! Hopefully I left nothing out and all will work for you! :)

You should now have the same menu that appears only while inside of a group for your views and the link on the menu is automatically created for passing the correct GID to the view. Also, your view will stay inside of the group. And last but not least this shows you how to finally have view listings of each separate content type. i.e. creating separate listing for all stories, books, audio, etc that is posted inside of the group.

Hope this helps!

P.S... Please pardon the fact that this was long as I am not the best as far as writing instructions.

-- Dave

ldway’s picture

Almost forgot to mention...

Please let me know if these instructions are clear enough and everything works as advertised. I will eventually put this in the Drupal Handbook under the How-To section once I am sure it is at a readable and understandable state.

Thanks,

-- Dave

j_orbin’s picture

Dave -

Brilliant, absolutely brilliant! Thank you very much for your complete explanation. I am going to implement this as soon as possible and I'll let you know how I get on.

Thanks-
Jim

henns20’s picture

Sweet Ginger Brown! it worked on first go:) <---flamingo kid reference

your post has handbook written all over it....great post!....it was a great work around for not being able to use the more link for panels blocks on OG....The only thing i did different was to use the code to create an inline list above the panels....instead of creating the block....again thanks ... your post is a great representation of the strength of the Drupal community:)

jamie

ldway’s picture

Glad to see it helped ya Jamie...

One thing I might mention is that using the code for making the menu blocks, with a few little changes you can use the same idea for creating a control panel at the top of all your group pages. For example, you could have icons at the top of every page on groups that represent your section listings such as stories, books, blogs, etc. All you have to do is in the header section of each view put your code for your icons and the links will be created automatically. You could make them different for each view. The point is that you really can do a lot using this type of basic code to make your group pages look good with all the links and views you need. And this really shows how powerful Drupal really is. ;)

henns20’s picture

ya it was great
I have used the header section before....Now when you say

All you have to do is in the header section of each view put your code for your icons and the links will be created automatically.

Do you mean PHP code or CSS HTML code? I am trying to picture it
Jamie

ldway’s picture

I was talking about adding php code to the header section of each view. For example, say you wanted a control panel at the top of each view to display some small pictures that link to other pages within the group. Perhaps another view. So, you could using the exact same php code do something like this....

PHP CODE:

if (module_exists('og')) {
  $group_node = og_get_group_context();
  $gid02 = $group_node->nid;
  $gid = (int)$gid02;
  if ($gid02 === null) $gid = 0;
  $output .= "<a href=\"http://YOUR_SITE.COM/YOUR_LINK_TO_OTHER_VIEW/$gid\"><img border=\"0\" src=\"http://YOUR_SITE.COM/YOUR_IMAGE.gif\" width=\"81\" height=\"81\"></a>";
print $output;
}

Notice how the only thing that was changed from the code before is what is in the $output section. All that was done is having an picture displayed that linked to another view and again the gid was automatically created.

Hope that all made sense!

SomebodySysop’s picture

That's not all you can use that views header for. Before dnosker came along with the cool code to create the block, the following is what I put into the view "header" and "empty" fields in order to display the group content on the home page:

global $current_view;
print t("<table width=100% BORDER=0 CELLPADDING=10>");
print t("< col width=50% >");

print t("<tr><td valign='top'>");
  $viewname = 'OGPages';
  $result = og_user_roles_checkview($viewname, $current_view->args);
  if ($result == 1) {
    print t("<p>&nbsp;</p>");
    print t("<hr>");
    print t("<h2>" . l('Pages','og/ogpages/' . $current_view->args[0]) . "</h2>");
    print t("<hr>");
    $view = views_get_view($viewname);
    print views_build_view('embed', $view, $current_view->args, 2, 6);
  }
print t("</td>");

print t("<td valign='top'>");
  $viewname = 'OGNews';
  $result = og_user_roles_checkview($viewname, $current_view->args);
  if ($result == 1) {
    print t("<p>&nbsp;</p>");
    print t("<hr>");
    print t("<h2>" . l('News','og/ognews/' . $current_view->args[0]) . "</h2>");
    print t("<hr>");
    $view = views_get_view($viewname);
    print views_build_view('embed', $view, $current_view->args, 3, 6);
  }
print t("</td></tr>");

print t("<tr><td valign='top'>");
$viewname = 'OGBlogs';
$result = og_user_roles_checkview($viewname, $current_view->args);
  if ($result == 1) {
    print t("<p>&nbsp;</p>");
    print t("<hr>");
    print t("<h2>" . l('Blogs','og/ogblogsexpanded/' . $current_view->args[0]) . "</h2>");
    print t("<hr>");
    $view = views_get_view($viewname);
    print views_build_view('embed', $view, $current_view->args, 4, 6);
  }
print t("</td>");

print t("<td valign='top'>");
$viewname = 'OGVideos';
$result = og_user_roles_checkview($viewname, $current_view->args);
  if ($result == 1) {
    print t("<p>&nbsp;</p>");
    print t("<hr>");
    print t("<h2>" . l('Videos','og/ogvideos/' . $current_view->args[0]) . "</h2>");
    print t("<hr>");
    $view = views_get_view($viewname);
    print views_build_view('embed', $view, $current_view->args, 5, 6);
  }
print t("</td></tr>");

print t("<tr><td valign='top'>");
$viewname = 'OGForums';
$result = og_user_roles_checkview($viewname, $current_view->args);
  if ($result == 1) {
    print t("<p>&nbsp;</p>");
    print t("<hr>");
    print t("<h2>" . l('Forum Topics','og/ogforums/' . $current_view->args[0]) . "</h2>");
    print t("<hr>");
    $view = views_get_view($viewname);
    print views_build_view('embed', $view, $current_view->args, 6, 6);
  }
print t("</td>");

print t("<td valign='top'>");
$viewname = 'OGLinks';
$result = og_user_roles_checkview($viewname, $current_view->args);
  if ($result == 1) {
    print t("<p>&nbsp;</p>");
    print t("<hr>");
    print t("<h2>" . l('Links','og/oglinks/' . $current_view->args[0]) . "</h2>");
    print t("<hr>");
    $view = views_get_view($viewname);
    print views_build_view('embed', $view, $current_view->args, 7, 6);
  }
print t("</td></tr>");

print t("</table>");
print t("<hr>");

$gid = $current_view->args[0];

if (module_exists("og_vocab")) {
  // First get the count of og_vocab terms for this group
  $query = "SELECT count(*) FROM {term_data} td INNER JOIN {og_vocab} ogv ON td.vid  = ogv.vid WHERE ogv.nid = %d";
  $counts = db_query($query, $gid);
  $n = db_fetch_object($counts);
  $count = $n->{"count(*)"};

  // If there is a count, then get the name(s) of the term(s)
  if ($count > 0) {
	$column = 0;
    print "<table width=100% BORDER=1 CELLPADDING=5>";
    print t("< col width=33% >");
    $viewname = 'OGVocab';
	$args = array();

    $query = "SELECT name,tid FROM {term_data} td INNER JOIN {og_vocab} ogv ON td.vid  = ogv.vid WHERE ogv.nid = %d ORDER BY td.name";
    $names = db_query($query, $gid);

    while ($item = db_fetch_object($names)) {
      $args[0] = $item->tid;
      $result = og_user_roles_checkview($viewname, $args);
      if ($result == 1) {
        if ($column == 0) print "<TR>";
        print "<td valign='top'><hr><b>" . $item->name . "</b><hr>";
        $view = views_get_view($viewname);
        print views_build_view('embed', $view, $args, $item->tid, 10);
        print "</td>";
	    $column++;
	    if ($column == 3) {
	      print "</TR>";
          $column = 0;
	    }
      }
    }
    if ($column > 0) print "</TR>";
    print "</table>";
    print t("<hr>");
  }
}

Now, adding on to dnosker's code, I have a place to put that link to the group home page that will always be present. Am I the only one bummed out by the fact that there's no Group Home Page link on the Group navigation menu?

/*
 * Create a link on the OG home page that links to a view of the OG content
 * As per http://drupal.org/node/174563
 */
  if (module_exists('og')) {
    $group_node = og_get_group_context();
    $gid02 = $group_node->nid;
    $gid = (int)$gid02;
    if ($gid02 === null) $gid = 0;
    $output .= "<ul>";
    $output .= "<div class=\"item-list\"><li><a title=\"Group Home Page\" href=\"http://www.mysite.com/node/$gid\">$group_node->title Home Page</a></li></div>";
    $output .= "<div class=\"item-list\"><li><a title=\"Listing of Articles\" href=\"http://www.mysite.com/og/ogarticles/$gid\">Articles</a></li></div>";
    $output .= "<div class=\"item-list\"><li><a title=\"Listing of Blogs\" href=\"http://www.mysite.com/og/ogblogs/$gid\">Blogs</a></li></div>";
    $output .= "<div class=\"item-list\"><li><a title=\"Group Calendar\" href=\"http://www.mysite.com/og_calendar/$gid\">Calendar</a></li></div>";
    $output .= "<div class=\"item-list\"><li><a title=\"Listing of Events\" href=\"http://www.mysite.com/og/ogevents/$gid\">Events</a></li></div>";
    $output .= "<div class=\"item-list\"><li><a title=\"Listing of Images\" href=\"http://www.mysite.com/og/ogimages/$gid\">Images</a></li></div>";
    $output .= "<div class=\"item-list\"><li><a title=\"Listing of Links\" href=\"http://www.mysite.com/og/oglinks/$gid\">Links</a></li></div>";
    $output .= "<div class=\"item-list\"><li><a title=\"Listing of News\" href=\"http://www.mysite.com/og/ognews/$gid\">News</a></li></div>";
    $output .= "<div class=\"item-list\"><li><a title=\"Listing of Newsletter Issues\" href=\"http://www.mysite.com/og/ognewsletters/$gid\">Newsletters</a></li></div>";
    $output .= "<div class=\"item-list\"><li><a title=\"Listing of Photo Albums\" href=\"http://www.mysite.com/og/ogalbums/$gid\">Photo Albums</a></li></div>";
    $output .= "<div class=\"item-list\"><li><a title=\"Listing of Pages\" href=\"http://www.mysite.com/og/ogpages/$gid\">Pages</a></li></div>";
    $output .= "<div class=\"item-list\"><li><a title=\"Listing of Videos\" href=\"http://www.mysite.com/og/ogvideos/$gid\">Videos</a></li></div>";
    $output .= "</ul>";
    print $output;
  }
ldway’s picture

That was some great code to share! Loved it!

You Wrote:
"Am I the only one bummed out by the fact that there's no Group Home Page link on the Group navigation menu?"

Yes! And that is just one of the reasons I ended up getting rid of Group Navigation Menu and replacing it with my own using the techniques above...

While we are all in the mood for sharing tips and tricks, here is another little thing I have done...

NOTE: I don't want to get off topic too much but the following is kind of a reverse of this thread which has some merit to mention. i.e. "create a link on NON OG pages that links to a users OG home page"

What I needed:

1... A menu on non group (normal site) pages that would have "My Group". This would be for the users Main group they wanted to be identified with.

2... Make it so that when a user logs into the system, they are taken to their main group home page.

So here is how I accomplished this. (Might be easier ways to do this but this works for me)

----------------
Main Group ID
----------------
This was pretty simple. I just added a field to profiles. "main_group_id". Then each user can simply have the node ID of their main group. Example: Main Group: 1325

----------------
For the menu:
---------------

I made a block that displays a few important items for users. This includes a log off link and a few other items. Most important is the link to the members main group page...

Block Description: Member Menu
Block Title: Member Menu

In the Block body goes my PHP CODE:

$home_group_url = "http://MYSITE.COM";  
global $user;
  if (!$user->profile_main_group_id == "") {
    $home_group_url = "http://MYSITE.COM/node/";
    $home_group_url .= $user->{profile_main_group_id};
  } 
  
 // Create menu block
  
$output .= "<div class=\"content\">
<ul class=\"menu\">
<li><a title=\"My Main Group\" href=\"$home_group_url\">My Main Group</a></li>
<li><a title=\"My Account Settings\" href=\"http://MYSITE.COM/?q=user\">My Account</a></li>
<li><a title=\"Log Off The System\" href=\"http://MYSITE.COM/logout\">Log Out</a></li>
</ul>
</div>";
print $output;

That takes care of having a little custom menu for the user that contains a link to their main group.

Now for the auto login to take them to that main group...

I simply use the "Login destination" module and in the settings to specify where exactly the user should be redirected upon login, I put the following

PHP CODE

global $user;
  if (!$user->profile_main_group_id == "") {
    $home_group_url = "http://MYSITE.COM/node/";
    $home_group_url .= $user->{profile_main_group_id};
  } else {
    // go to the home page
    $home_group_url = "http://MYSITE.COM";
}
return $home_group_url;

NOTE: the "Login destination" module does not allow putting opening ?php and ending ?> ... I just put that here to auto highlight the block of code.

And there you have it! There is my little contribution for today. :)

-- Dave

henns20’s picture

awesome!!!.... man this really helps in getting to next level of practical php--- great stuff - i am going to work through this ...this weekend- kudos for the thorough explanations

gracearoha’s picture

Excellent instructions, Dave! Thanks so much for sharing that valuable snippet :)

Steel Rat’s picture

This would be fantastic if only I could get the Arguments section to allow me to add arguments. It's been really frustrating with the Views module that sometimes it doesn't give the appropriate options in the different sections. e.g. sometimes I can't add fields because there are no options to add them, other times I can't add arguments or filters, the forms just don't appear. AAAARRRRGGGGHHH!!

bjacob’s picture

I think I just need some more hints to understand the concept. Maybe you can help me. What did I do:

  1. Created a new content type "animals" and assigned it as "Group home page node type". I didn't change the view for group home page.
  2. Installed pathauto and created a rule which sets up paths for og: "animals/[title-raw]". I've also tried "animals/[ogname-raw]" but it didn't work.
  3. Created a new view called "animals_list". This view provides a page, the URL is "animals". I've created a new menu item "Animals" which links to this URL.
  4. When I go to /animals all groups of the content type "animals" are displayed. I click on a link to a group and the group is displayed in the style of the group home page view. So far everything is fine.
  5. I've created additional views. One is called "animals_tools". It also provides a page, the URL is "animals/$group/tools". I've also checked "Provide Menu", "Provide Menu as Tabs", entered a Menu Title, supplied an argument "OG: Group nid(s)" where title is %1. All the other views are similiar.
  6. Now the trouble begins. When I go to /animals and click on a group link the menu tabs are not displayed (URL is /animals/dog). When I go to /animal/12/tools (where 12 is the id of the group node "dog") I can see the menu tabs of the different views but no group home page is there anymore. The other views show data but I have no idea how to combine the group home page with my other views using the view menu system.

As you can see I've done something... for sure something wrong. What am I missing? Can anyone help me please?

WISEOZ’s picture

I noticed just one limitation with the appending the view URL with "og" method. Some of the OG views I created are set up to create tabs on the OG home page using the "node/$group/custom" approach, which is explained under the URL field on the View form. Changing this to "og/node/$group/custom" or "og/$group/custom" simply sends the user back to the main OG directory. If anyone knows of a means of keeping the tabs while also having the "More" connect correctly through Panels, I'd be interested in knowing.

On a related topic, I'm also looking for a means of placing the "Create Story", "Create Page", etc links in the header or footer of a view while also obeying the arguments it sends.

najibx’s picture

We used OG and Domain module for our Malaysia Golf Portal.
We really need to improve the interface to something like myspace/facebook group interface. Currently just simply use the default view.
would like to try with panel2, views & OG.

henns20’s picture

you know that you can do that now - with a little tweaking ---it is not a perfect solution but i have - just use node-groups.tpl.php to insert the panel page.....if you would like i can post the post the link - to the discussion on it....plus Moshe weitzman said that they is OG-panels module out there but I haven't seen it yet...may be he meant it was drupal 6

WISEOZ’s picture

Yes, please post it!

henns20’s picture

http://drupal.org/node/173473 first one

http://drupal.org/node/166119 this is the one that completses the first

moshe weitzman’s picture

Status: Active » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)

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

SocialNicheGuru’s picture

subscribing

scedwar’s picture

subscribing

scedwar’s picture

To create a link to create content in the group, or a view header just do:

$group_node = og_set_group_context();
$gid = $group_node->nid;
?>
<a href="/node/add/page?gids[]=<?php echo $gid; ?>">Add Page to group</a>

We have also used nice tricks to alert users to the fact that they are an admin for a group in the view header. Alternatively, that they haven't posted any content in the group that would show in that view (put this in the empty text for the view, modify for the header etc):

The group have not added any xyz_type nodes yet. 
<?php
//check we've got a group, rights to view the group, and of the right typ (if you have multiple group types)
if (($group = og_get_group_context()) && node_access('view', $group) && ($group->type == 'myogtype') ) {
 //check current user is admin
 if (og_is_node_admin($group)) {
$group_id = $group->nid;
$message_out = "You are a Group Admin. <br>Your group have not entered any pages of this type yet. <a href=\"/node/add/page?gids[]=$group_id\">Add your first Page</a>.";
 drupal_set_message($message = $message_out, $type = 'error');
} 
}
?>
Rosamunda’s picture

Genius. Just genius.
Thanks, many, many, MANY THANKS Dave!!!
Your explanation was clean, clear, and effective. It works like a charm.

Thanks!!
Rosamunda

Lioz’s picture

great tutorial!

just one question: what about breadcrumbs?

when i'm on a grooup post i correctly see: "groups>group>"

when i click on the stories i lost the group context (i see only "groups")

i think that i should see "groups>group>stories"

what do you think?

scedwar’s picture

Breadcrumbs are a nightmare with views. We solved the problem for nodes with the custom breadcrumbs module, however, for the views we are still working on it! If anyone can suggest a link, I'd be very grateful, but this discussion in the Custom Breadcrumbs issue queue suggests nobody has it yet: http://drupal.org/node/215475

ln282’s picture

Subscribing.

daniel-san’s picture

Title: create a link on the OG home page that links to a view of the OG content » Thank you

Thanks for posting this. Very applicable to a project I am working and that I've been battling with understanding how to make it work. So, so thankful!!!

- Dan

daniel-san’s picture

Title: Thank you » create a link on the OG home page that links to a view of the OG content

Changed title back to original. Sorry about that.

izmeez’s picture

subscribing

pyxio’s picture

This is some excellent stuff. Thanks for sharing the recipe ldway. While on the subject of custom menus, you have shown us how to link to new pages of a content type. How about the link format for pages already generated by og itself? I'd like to throw away the og menu completely. Most specifically, I'm interested in the link format for the group's homepage, the invitation page, the forum page and the members page. I'd like to mix these into my menu for custom contact I created using your recipe above. Thank you very much for the help! Cheers, Kevin

lelizondo’s picture

I just want to add that it is not necessary to set the views path to og/something/%.. I use groups/%/stories and then the pathauto for stories is something like groups/[group-id]/stories/[nid]

This way is easier to set the breadcrumb using the path.

izmeez’s picture

subscribe

morbiD’s picture

The solution in #9 looks like it almost exactly covers what I want to do but I have an additional issue which I'm unsure about.

I am using the subdomain module to assign each organic group to it's own subdomain i.e. to get to group1 you go to group1.example.com and to get to group2 you go to group2.example.com.

As this thread has discussed, I would like views for listing each content type within the current group, but I would preferably like to get to them via links like group1.example.com/news, group1.example.com/letters and group1.example.com/events.

However, from #9:

For the URL field make it "og/ogstories" (IMPORTANT, you must start the url out with "og" or this will not keep you in the group when the view is run!

This makes it sound like what I'm trying to achieve is impossible. Any ideas?

ln282’s picture

This thread has been very helpful to me. I'm using the solution in #9, but wanted the menu to only be seen by group members, and have non-members see a link to the group membership request page instead.

To do this, I added:
if (og_is_group_member($gid)) {
above "$output .= ... "
and then above "print $output", added:

 }
else {
$output=" <a href=\"http://www.mysite.com/og/subscribe/$gid?destination=og\"><b>Join This Group</b></a>";
}

It seems like a simple thing in retrospect, but it took me a while to get here, so I thought I might save a fellow newb some trouble.

riddhi_uppal’s picture

As specified in #9 to use the filter i.e. Add a filter for "OG: Posts in current group" Operator set to "Is Equal To" and value "Current Group" is not working for me. When I select this filter then it not shows anything to select for "equal to" , its rather give option for expose.

We are working in Drupal 6.x

Kindly suggest.

lias’s picture

Awesome, this is exactly what I'd been looking for! Thanks Dave for the great instructions.

Edit 071310:

One more thing you can add to your block of group pages is a link to the group homepage (Drupal 5.x):

<?php if (($node = og_get_group_context()) && node_access('view', $node)) : ?>           <?php $group_nid = og_get_group_context()->nid; ?>
<div><a class="og_link" href="/node/<?php print $group_nid;?>">Home</a></div>
<?php endif; ?>
ivan011’s picture

Hi, I'm new into Drupal (and php) world and for sometime I was struggling with one issue...I used solution #9 and it works ok. Links in menu are in form http://mysite/og/ogstories/$gid , and if I understand $gid is id number of a group. But is it possible (I suppose it's possible) to have group name within link instead of id number of a group. So instead of http://mysite/og/ogstories/123 to have ie http://mysite/og/ogstories/group_name. Also, is it possible to have something else then "/og/" within link?

Thanks (and thanks for earlier posted solutions)

Drake’s picture

subscribed

greta_drupal’s picture

subscribed

drunkencelt’s picture

Here is the code I have used to get this functionality to work in Drupal 7 based on #9.

You will note the function that returns the Group ID (gid) has changed for D7. I have also added in $base_url to the outputted link so you will not have to manually update your links in the event your site URL changes, for example moving from localhost to production etc.

My views are embedded in a node (view field) hence the node id in the url otherwise everything else is the same.

<?php
global $base_url;
  if (module_exists('og')) {  
  $context = og_context($group = NULL);
  $gid02 = $context->gid;  
  $gid = (int)$gid02;  
    if ($gid02 === null) $gid = 0;    
  $output = "<div class=\"item-list\"><li><a title=\"Listing of Stories\" href=\"$base_url/node/90/$gid\">Overview</a></li></div>";
print $output;
}
?>

I should also add that you will not need the second part of the PHP provided to control visibility if you use a node to display your views (view field module) as you can limit the display to a specific content type as part of D7 core.

Hope this helps.

namita21’s picture

@ drunkencelt - I tried using above code in one of the view of the list of all the pages under a group in header section and I am getting below error:

Parse error: syntax error, unexpected T_STRING in /var/www/html/modules/php/php.module(80) : eval()'d code on line 8

is it related to the code???

I am not really sure what I am missing here, any help is appreciable.

namita21’s picture

Version: master » 7.x-2.4
Issue summary: View changes
Status: Closed (fixed) » Active
lias’s picture

Hi, here's the view I use in Drupal 7x24 to display the name of the group in a block as well as a block that displays contact information.

Please note that the fields are specific to my install, you can remove once you've imported. I'm using the latest views and og modules.

$view = new view();
$view->name = 'og_name';
$view->description = 'Block title displays Group Name  and Block Contact displays map and address';
$view->tag = 'og';
$view->base_table = 'node';
$view->human_name = 'OG Name - Contact';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'OG Name';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['distinct'] = TRUE;
$handler->display->display_options['query']['options']['pure_distinct'] = TRUE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'some';
$handler->display->display_options['pager']['options']['items_per_page'] = '1';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Relationship: OG membership: OG membership from Node */
$handler->display->display_options['relationships']['og_membership_rel']['id'] = 'og_membership_rel';
$handler->display->display_options['relationships']['og_membership_rel']['table'] = 'node';
$handler->display->display_options['relationships']['og_membership_rel']['field'] = 'og_membership_rel';
/* Relationship: OG membership: Group Node from OG membership */
$handler->display->display_options['relationships']['og_membership_related_node_group']['id'] = 'og_membership_related_node_group';
$handler->display->display_options['relationships']['og_membership_related_node_group']['table'] = 'og_membership';
$handler->display->display_options['relationships']['og_membership_related_node_group']['field'] = 'og_membership_related_node_group';
$handler->display->display_options['relationships']['og_membership_related_node_group']['relationship'] = 'og_membership_rel';
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['relationship'] = 'og_membership_related_node_group';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
$handler->display->display_options['fields']['title']['element_label_colon'] = FALSE;
/* Contextual filter: Content: Nid */
$handler->display->display_options['arguments']['nid']['id'] = 'nid';
$handler->display->display_options['arguments']['nid']['table'] = 'node';
$handler->display->display_options['arguments']['nid']['field'] = 'nid';
$handler->display->display_options['arguments']['nid']['default_action'] = 'default';
$handler->display->display_options['arguments']['nid']['title_enable'] = TRUE;
$handler->display->display_options['arguments']['nid']['title'] = '%1';
$handler->display->display_options['arguments']['nid']['default_argument_type'] = 'og_context';
$handler->display->display_options['arguments']['nid']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['nid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['nid']['summary_options']['items_per_page'] = '25';
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;

/* Display: Block - OG Mast */
$handler = $view->new_display('block', 'Block - OG Mast', 'block_2');
$handler->display->display_options['defaults']['title'] = FALSE;
$handler->display->display_options['display_description'] = 'Working Block to Display Group Name on Group Pages';
$handler->display->display_options['defaults']['hide_admin_links'] = FALSE;
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['style_options']['default_row_class'] = FALSE;
$handler->display->display_options['style_options']['row_class_special'] = FALSE;
$handler->display->display_options['defaults']['style_options'] = FALSE;
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
$handler->display->display_options['row_plugin'] = 'fields';
$handler->display->display_options['row_options']['default_field_elements'] = FALSE;
$handler->display->display_options['defaults']['row_options'] = FALSE;
$handler->display->display_options['defaults']['fields'] = FALSE;
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['relationship'] = 'og_membership_related_node_group';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['alter_text'] = TRUE;
$handler->display->display_options['fields']['title']['alter']['text'] = '<div id="og_mast">[title]</div>';
$handler->display->display_options['fields']['title']['alter']['path'] = '[title]';
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
$handler->display->display_options['fields']['title']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['title']['element_default_classes'] = FALSE;
$handler->display->display_options['defaults']['arguments'] = FALSE;
/* Contextual filter: OG membership: Group ID */
$handler->display->display_options['arguments']['gid']['id'] = 'gid';
$handler->display->display_options['arguments']['gid']['table'] = 'og_membership';
$handler->display->display_options['arguments']['gid']['field'] = 'gid';
$handler->display->display_options['arguments']['gid']['relationship'] = 'og_membership_rel';
$handler->display->display_options['arguments']['gid']['default_action'] = 'default';
$handler->display->display_options['arguments']['gid']['default_argument_type'] = 'og_context';
$handler->display->display_options['arguments']['gid']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['gid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['gid']['summary_options']['items_per_page'] = '25';
$handler->display->display_options['block_description'] = 'OG Name Mast';

/* Display: Block - OG Contact */
$handler = $view->new_display('block', 'Block - OG Contact', 'block_1');
$handler->display->display_options['defaults']['title'] = FALSE;
$handler->display->display_options['display_description'] = 'Display Group Contact Info on Group Pages';
$handler->display->display_options['defaults']['hide_admin_links'] = FALSE;
$handler->display->display_options['defaults']['fields'] = FALSE;
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['relationship'] = 'og_membership_related_node_group';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['exclude'] = TRUE;
$handler->display->display_options['fields']['title']['alter']['alter_text'] = TRUE;
$handler->display->display_options['fields']['title']['alter']['text'] = '<div class="contacttitle">Contact Information</div>';
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
$handler->display->display_options['fields']['title']['element_label_colon'] = FALSE;
/* Field: Content: Park Hours */
$handler->display->display_options['fields']['field_office_hours']['id'] = 'field_office_hours';
$handler->display->display_options['fields']['field_office_hours']['table'] = 'field_data_field_office_hours';
$handler->display->display_options['fields']['field_office_hours']['field'] = 'field_office_hours';
$handler->display->display_options['fields']['field_office_hours']['relationship'] = 'og_membership_related_node_group';
$handler->display->display_options['fields']['field_office_hours']['label'] = '';
$handler->display->display_options['fields']['field_office_hours']['exclude'] = TRUE;
$handler->display->display_options['fields']['field_office_hours']['alter']['alter_text'] = TRUE;
$handler->display->display_options['fields']['field_office_hours']['alter']['text'] = '[field_office_hours]<br>';
$handler->display->display_options['fields']['field_office_hours']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_office_hours']['hide_empty'] = TRUE;
/* Field: Content: Location Name */
$handler->display->display_options['fields']['field_location_reference']['id'] = 'field_location_reference';
$handler->display->display_options['fields']['field_location_reference']['table'] = 'field_data_field_location_reference';
$handler->display->display_options['fields']['field_location_reference']['field'] = 'field_location_reference';
$handler->display->display_options['fields']['field_location_reference']['relationship'] = 'og_membership_related_node_group';
$handler->display->display_options['fields']['field_location_reference']['label'] = '';
$handler->display->display_options['fields']['field_location_reference']['exclude'] = TRUE;
$handler->display->display_options['fields']['field_location_reference']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_location_reference']['type'] = 'entityreference_entity_view';
$handler->display->display_options['fields']['field_location_reference']['settings'] = array(
  'view_mode' => 'teaser',
  'links' => 0,
);
/* Field: Content: Email */
$handler->display->display_options['fields']['field_email']['id'] = 'field_email';
$handler->display->display_options['fields']['field_email']['table'] = 'field_data_field_email';
$handler->display->display_options['fields']['field_email']['field'] = 'field_email';
$handler->display->display_options['fields']['field_email']['relationship'] = 'og_membership_related_node_group';
$handler->display->display_options['fields']['field_email']['label'] = '';
$handler->display->display_options['fields']['field_email']['exclude'] = TRUE;
$handler->display->display_options['fields']['field_email']['alter']['alter_text'] = TRUE;
$handler->display->display_options['fields']['field_email']['alter']['text'] = '[field_email]<br>';
$handler->display->display_options['fields']['field_email']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_email']['hide_empty'] = TRUE;
/* Field: Content: Fax */
$handler->display->display_options['fields']['field_fax']['id'] = 'field_fax';
$handler->display->display_options['fields']['field_fax']['table'] = 'field_data_field_fax';
$handler->display->display_options['fields']['field_fax']['field'] = 'field_fax';
$handler->display->display_options['fields']['field_fax']['relationship'] = 'og_membership_related_node_group';
$handler->display->display_options['fields']['field_fax']['label'] = '';
$handler->display->display_options['fields']['field_fax']['exclude'] = TRUE;
$handler->display->display_options['fields']['field_fax']['alter']['alter_text'] = TRUE;
$handler->display->display_options['fields']['field_fax']['alter']['text'] = 'Fax: [field_fax]<br>';
$handler->display->display_options['fields']['field_fax']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_fax']['hide_empty'] = TRUE;
$handler->display->display_options['fields']['field_fax']['click_sort_column'] = 'number';
$handler->display->display_options['fields']['field_fax']['type'] = 'local_phone_number';
/* Field: Field: Phone */
$handler->display->display_options['fields']['field_phone']['id'] = 'field_phone';
$handler->display->display_options['fields']['field_phone']['table'] = 'field_data_field_phone';
$handler->display->display_options['fields']['field_phone']['field'] = 'field_phone';
$handler->display->display_options['fields']['field_phone']['relationship'] = 'og_membership_related_node_group';
$handler->display->display_options['fields']['field_phone']['label'] = '';
$handler->display->display_options['fields']['field_phone']['alter']['alter_text'] = TRUE;
$handler->display->display_options['fields']['field_phone']['alter']['text'] = '<div id="contact">[title]
<div  class="side">
[field_office_hours]
[field_email]
Phone: [field_phone]<br>
[field_fax]
[field_location_reference]
</div></div>';
$handler->display->display_options['fields']['field_phone']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_phone']['click_sort_column'] = 'number';
$handler->display->display_options['fields']['field_phone']['type'] = 'local_phone_number';
$handler->display->display_options['defaults']['arguments'] = FALSE;
/* Contextual filter: OG membership: Group ID */
$handler->display->display_options['arguments']['gid']['id'] = 'gid';
$handler->display->display_options['arguments']['gid']['table'] = 'og_membership';
$handler->display->display_options['arguments']['gid']['field'] = 'gid';
$handler->display->display_options['arguments']['gid']['relationship'] = 'og_membership_rel';
$handler->display->display_options['arguments']['gid']['default_action'] = 'default';
$handler->display->display_options['arguments']['gid']['default_argument_type'] = 'og_context';
$handler->display->display_options['arguments']['gid']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['gid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['gid']['summary_options']['items_per_page'] = '25';
$handler->display->display_options['block_description'] = 'OG Contact';