Hi,

I am trying to create some custom views for my groups. I have several content types that can be posted into a group, i.e. forum posts, events, files.

I want to create a view that shows, for example, all forum posts from group x, then all events from group x, etc.

I have created the views, but am having difficulty getting the group name to show in the view title and the URL. The view URLs are in the form of "group/groupid/forum", so for example the group with group audience id of 5 shows all its forum posts at the URL group/5/forum. What I'd like to do if it's possible is for the URL to take the form of group/groupname/forum, and for the group name to be the view title as well.

I've attached some screenshots of what I have been driving myself mental trying to achieve. If anyone could offer any advice (or even how to achieve this with panels, although I'd like to do it with views as I'm almost there with it) I would be eternally grateful.

I figure the answer lies with some custom argument code which is out of the scope of my abilities, and I can't find any snippets anywhere. Also, my examples originally showed the view title as "groupid forum", i.e. "5 forum" where gid = 5, but I've actually managed to stuff that up as well so that the title is now % forum... help!!

Again, if anyone can help, that would be great. Thanks.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Sherbet’s picture

I've been troubled by this very issue for quite a while now, with no solution thus far. In my case, I'd like to create a group-specific calendar at groups/groupname/calendar. But I can only do it via gid...

Hopefully someone has a solution.

laryn’s picture

Working on a similar problem but haven't cracked it yet. Updating the URL would be cool, but I'd settle for being able to override the title in a meaningful way (e.g. something that brings more clarity than "11 Calendar").

benjohnstone’s picture

Any news on this?. I'd really like this functionality as well.

Sherbet’s picture

I've been using it in panels with the GID as argument in my content pane, and then have it converted to Groupname. That works quite well for me.

johnlutz’s picture

@Eternityempire, can you elaborate on your setup?

ultimike’s picture

I agree with @johnlutz - I'd love to hear more about @eternityempire's configuration.

Thanks,
-mike

amitaibu’s picture

Version: 7.x-1.4 » 7.x-2.x-dev
Status: Active » Fixed

I'm switching this into a support for 7.x-2.x (and I hope you guys switch to the version as-well ;), but it's the same answer

What I'd like to do if it's possible is for the URL to take the form of group/groupname/forum, and for the group name to be the view title as well.

It's not possible out of the box, the same way as it's not possible for "regular" node titles. They are not unique, so Views can translate the string to node ID.

However, here's a quick recipe:

  • Add a text field to the node called "field_clean_title"
  • On hook_node_presave() you can ctools_cleanstring() the $node->title and keep the value there. It's also up to you to make sure it's unique, by EntityFieldQuery possible matches and suffixing the string with numbers.
  • So now you can add that "clean-title" in the URL, and in the Views argument used that field to get your node.
ultimike’s picture

FileSize
166.36 KB

Amitaibu,

Thanks for the quick response, but while your solution isn't what I'm looking for, it did help me find something that works for me. In my case, I'm not concerned with the URL, I just want to be able to override the view's title when a contextual filter value is available.

In my case, I have a content pane Views display that displays nodes of type "blog entries". I've added the "OG membership: OG membership from Node" relationship, and a "(OG membership from node) OG membership: Group ID" contextual filter. I pass in the argument via a panels context. This works as expected, only displaying blog entries related to the current group.

What I'd like to do is to override the view title to be something like "[group name]'s Blog Entries". But, as you expect, when I override the node title from the contextual filter settings, I get "[group id]'s Blog Entries".

Attempting to apply what you mentioned in comment 7 above doesn't really help me, because I need to get to the Group node through the relationship, and none of the Group's fields are available. When I try to add the field_clean_title contextual argument, it doesn't allow me to choose a relationship :(

*BUT*, your solution did let me know that I was using the wrong contextual filter. Instead of using the Group ID, I needed to use a unique, clean version of the Group title. In my case, I'm lucky because only site admins have the ability to create new groups, so I just decided to use the "Content: title" field directly. I'll inform the site admins of the rules about keeping group titles clean and unique (your point about ensuring that there's a clean, unique version of the title is important).

Before I added that contextual filter, I added a second relationship: "(OG membership from node) OG membership: Group Node from OG membership" - note that this uses the "OG membership: OG membership from Node" relationship I originally had. In effect, I'm chaining the two relationships. Then, when I add the "Content: title" contextual filter, I set it to use the "Group node from OG membership" relationship, then do the "override title" stuff. Works like a champ.

I've included a screenshot of my setup in hopes that it helps out someone else!

Thanks,
-mike

amitaibu’s picture

FileSize
431.85 KB

Happy I was able to help :)

btw, If you worry only about showing the title, but allow passing the node ID via URL, you can look at the Contextual filter of the view admin/structure/views/view/og_members/edit, which transforms the node ID to the node title.

Screenshot_5_9_13_9_14_AM.jpg

ultimike’s picture

Whoa whoa whoa!

So, what you're telling me is that if I "Specify validation criteria" for the "Group ID" contextual filter, then when I use "%1" in the "Override title", it magically replaces the Group ID with the Group name in the title?

Holy undocumented feature, Batman! (or is it documented somewhere that I've never seen?)

thanks,
-mike

amitaibu’s picture

So, what you're telling me is that if I "Specify validation criteria" for the "Group ID" contextual filter, then when I use "%1" in the "Override title", it magically replaces the Group ID with the Group name in the title?

Yes, that's a Views feature - you can do the same with any node title. Those validation handlers "know" how to turn those raw inputs to titles.

(or is it documented somewhere that I've never seen?)

Well, those default exported views are there mostly for people to learn those "how-to". Feel free to add docs in OG's documentation if you feel other can benefit from it.

ultimike’s picture

Amitai,

Thanks for the info - I think I'm going write a quick blog post about this...

I went ahead and updated the relevant page of Views' documentation to specify that in order for the id->name substitution to take place, the validation must be present.

Thanks,
-mike

Status: Fixed » Closed (fixed)

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

ashi anand’s picture

Hi,

I was struggling with this same issue for a long time, and could finally get something to make it work. I am now being able to get the organic group name displayed in views, along with using the name (instead of ids) in filters. This is the configuration I have used in Views, which is seeming to be working fine for me.

Since the group name, is actually nothing but a normal [node:title] the key was to set up a relationship that allows me to link the [content:title] to the organic group node. This was done by

(a) Relationship #1:-- First set up the relationship [OG membership: OG membership from Node]
(b) Relationship #2:-- Then set up the relationship [OG membership: group node from OG membership]... when setting up this relationship, you have an option for specifying a relationship, set this up to [OG membership from node]
(c) Now if you go to the field [Content:Title], you now have a relationship option called [group node from OG membership]... if you select this, the field will now display the group name as desired... this also works if you wish to use a filter with group names

I hope this helps. Please do let me know if this works for you, and also if anyone knows of any issue with this configuration.

Cheers,
Ashi.

Gil_Gamesh’s picture

Issue summary: View changes

Yes!

Thank you! Thank you!

This worked perfectly.

Gil