2

I'm using Organic Groups with Views in Drupal 7 with OG Tokens to create a view which returns all content with a type associated with it, so groups/foo/article would return all articles where the content type is article and the group is foo. This works fine for a group audience where the audience is one word, such as foo, or two run together without spaces, such as FooBar. However when I create a group like foo-bar, the view returns the no content page even when there is content attached the group. The contextual filter that I am using is OG Group: Label.

I've tried putting PHP to explode the results in the 'WHEN THE FILTER VALUE IS IN THE URL OR A DEFAULT IS PROVIDED', following the posts that I've seen but although I can see it printing out the "foo bar", it is not calling the types attached to the group. Is there somewhere else that I can explode this data and remove the spaces so that the group details can be presented in the view, or even look at the query to see what is being passed into it by the argument?

Thanks for your help and time.

UPDATE: Having run a slightly orthogonal search, i came across the following code:

    $handler->argument = str_replace('_', ' ', $argument);
    return TRUE;

Having replaced the underscore with a dash, the multi-worded OG audience type can be used as I outlined above. Put the code into the "PHP Validate" code on the specify validation code and apply. The original came from PixelClever . I'll mark as answered when the site allows me to do so as I don't have enough user points to do so immediately.

-1
  1. If the arguments are not in a taxonomy term then add a vocabulary to contain them
  2. Under the contextual filter section for When the filter value is in the URL check validation, set it to a Taxonomy term and pick the vocabulary.
  3. Select the Filter type or term name from the term ID
  4. Check the box for Transform Dashes.

The view should now read the name from the URL and access the term id.

  • I'm going to give it a go. I'm trying to get the content types related to the group (so all articles for that group for example) and don't quite see how adding a taxonomy term would help as it sets up the relationship between term id and type rather than group membership and type – ipe Nov 14 '11 at 19:42
  • Having run a slightly orthogonal search, i came across the following code: – ipe Nov 14 '11 at 19:49
  • What code? I see your problem. I was thinking the problem is that the URL has dashes between words (unless you set it otherwise) and will not compare with words with spaces. The only way I know to get Views to read a multi-word URL is with Taxonomies. Its kind of a hack, but.... – Ashlar Nov 15 '11 at 2:46
  • the code is in the above Update with the answer which I found to solve the problem in this case. Thanks for your suggestion though which I'm keeping in mind for something else. – ipe Nov 15 '11 at 8:14
  • Thanks for your research, I have been looking in the code for how to address URLS in views for several problems, and here is an answer right in the view! – Ashlar Nov 15 '11 at 14:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.