if a node access module is enabled (e.g Organic Groups) several nodes are not accessible to public. Please disable showing service links on private OG pages.


gemalm’s picture

I did the following and it works. In the option "Show Service Links on specific pages", I have selected the option "show if the following PHP code returns TRUE" and I add the following code:

$args = arg();
if($args[0] == 'node' && is_numeric($args[1])) {
  $n = node_load($args[1]); 
  if (property_exists($n, 'og_public')) {
  	return $n->og_public;  
    return true;
return false;
TheCrow’s picture

Category: feature » support
Status: Active » Closed (fixed)
chiebert’s picture

Title: Disable service links on non -public OG pages » Disable service links on non-public pages
Version: 6.x-2.x-dev » 7.x-2.x-dev
Status: Closed (fixed) » Needs review
1.41 KB

I'm coming here from #2009828: Add option to hide for pages that are not normally visible to anonymous users, where my original issue was also caused by the need to hide service links on private Organic Groups content in the 7.x branch. The PHP filter snippet approach in #1 is a bit problematic, especially for OG in D7:

  1. I can't remember how it works in OG 6.x, but this check only works for the Group Node itself - what about group content, which may or may not inherit the visibility settings of its container group?
  2. Re-loading the node object seems unnecessarily heavy
  3. The fields used in OG 7.x-1.x and 7.x-2.x are (potentially) quite different, and entering this PHP into the database as a setting makes it very hard to fix if OG changes yet again
  4. This only works for OG-related use cases. The o.p. actually starts with a generalised question: what if other node access modules are enabled? We need a generalised solution.

Instead, I suggest we use the Drupal-version-specific version of node_access(), with a user-configurable switch on the admin settings form analogous to the 'hide for unpublished content' check. The attached patch for 7.x-2.x adds this setting in service_links.admin.inc:

$form['how_to_show_the_links']['service_links_hide_if_private'] = array(
  '#type' => 'checkbox',
  '#title' => t("Don't show links if the content is inaccessible to anonymous users"),
  '#default_value' => variable_get('service_links_hide_if_private', 0),

... and then adds a check in function service_links_show(), in service_links.module:

if (variable_get('service_links_hide_if_private', FALSE) && (!node_access('view', $node, user_load(0)))) {
  return FALSE;

This is working well for me, but would need to be backported to 6.x.

Simon Georges’s picture

Category: support » feature

Moving to "Feature request".

Simon Georges’s picture

Due do the diversity of Drupal modules, it's kinda impossible to evaluate whether the node is public or not (since you can have temporary public node, special codes, GET parameters, ...), so I don't see how this can be build into the module.