0

I'm grateful for the amazing organic groups module (and so many other drupal modules), which I am using for a civil society and social economy network platform.

I have a question, which I think would be interesting for others too. I couldn't find the answer anywhere.

Usecase: I have a page (in page manager) which outputs a tab in og_group nodes, showing a view panel pane of og_group content (together with other panes). Specifically, og_group are organizations, and og_group contents are events. So I'm showing events of each organization in a separete tab.

I wish this tab "events" to be visibile only if there is at least one node of type "event" listed as group content of the og_group page being viewed.

In order to do this, I am trying to use page manager "access rules", which, to quote specific documentation:

are used to test if the page is accessible and any menu items associated with it are visible.

The "only" og related rules available are:

"Node is an OG group" "Node is an OG group content" "user membership in group" "user permissions in group"

So, I think my logic is possible with the generic "php code" rule. But I'm no coder, yet.

Anybody could give me a hint about what code should I write to check if te viewed node (which is an OG group) has at least one event associated with it as group content?

Thanks!!!

Config: D7 7.41, php 5.2.4, panopoly 7.x-1.28, og 7.x-2.7, ctools 7.x-1.8, panels 7.x-3.5

Update: as @Stefanos suggested in his answer, I am searching for a kind of "no results" behavior of views module, in page manager.

@Stefanos, here is the context available in the page: enter image description here

4
  • 1
    Hey Miro, could you post a list of the $contexts available in the php code rule? You need to have the devel module installed and then you could get them on your screen by placing this into the php textarea: dpm($contexts); Commented Mar 12, 2016 at 15:57
  • yes, thanks, I added a print screen in the question! Commented Mar 12, 2016 at 16:18
  • I didn't expand all objects in the picture, but inside data there is nid, for instance. I'm trying to evaluate something like this empty(views_get_view_result('rbv_view_group_content','panel_pane_3','$node->nid'));, with no success yet! It is the related view with contextual filter that I am trying to get. Commented Mar 12, 2016 at 16:27
  • 1
    Hey Miro, updated my answer below, you can try the code at the top. Commented Mar 12, 2016 at 16:35

1 Answer 1

1

Direct answer: To do this with the code you provided, you should use something like the following:

$node = $contexts['argument_entity_id:node_1']->data;
$args = array($node->nid‌​);
return empty(views_get_view_result('rbv_view_group_content','panel_pane_3',$args));

Alternative answer: I have an alternative suggestion, and unless you absolutely want to use the Page Manager, it should allow you to solve your problem without any coding.

So, if you read so far... :-), I would suggest using Views and setting up a path that will 'link' your view to your group node's URL. You are probably already using a view to list your Events. You can set up a page for that view that has a path like the following:

node/%nid/events

You should further configure your page to be rendered as a "Menu Tab", titled "Events".

This Views Page will now be linked to your Group page, and you will be able to handle its behaviour in the case of no results (Events) for that og_group node; for your case to simply hide it.

To get this all working, you would also need to set up your contextual filters to use the og_group nid.

This is a bit theoretical, but I am not entirely sure of your setup. I hope it helps you though!

13
  • Hi Stefano, thank you very much for your answer. Yes, if I would go for a views generated page, I believe your suggestion to configure the no results behavior is viable. Thanks! I wish to use page manager because it's a panopoly based website, so I use panels, and I wish to add more panel panes to the "events" page.. I will update my question. Any other good hint? :-) Commented Mar 12, 2016 at 15:24
  • Hi, and thanks again! I used the code you suggested, and the tab menu behave correctly, only being displayed in groups which has some events. But, when I hit the tab button, I have a 500 internal server error... Commented Mar 13, 2016 at 13:32
  • Hey @Miro, glad to know you are a step further. Since I don't know all the details of your panel, could you try disabling your panel's panes in order to find out which one is causing the problem? Then we can try to find out what is causing the 500 error. If you deactivate the selection php code, do you still get the error? Commented Mar 13, 2016 at 19:18
  • Ok, I did disabled all panel panes in the page. 500 still there. If I deactivate the php access rule, everything is visible, no errors, but on all pages. Same if I substitute php code with return true;. Commented Mar 13, 2016 at 23:21
  • My code is a bit different than what you suggested. I didn't use the array: return !empty(views_get_view_result('rbv_view_group_content','panel_pane_3', $contexts['argument_entity_id:node_1']->data->nid));. If I put the contextual filter inside an array, return !empty(views_get_view_result('rbv_view_group_content','panel_pane_3', array($contexts['argument_entity_id:node_1']->data->nid))); , I got the 500 in the page, plus a Warning in the main page saying: "array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 175 of /includes/entity.inc)." Commented Mar 13, 2016 at 23:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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