I am attempting to maintain an og_menu block on a view that is executed within group context.

I am using group url context detection format for view url (group/%/content) and I actually set the group context in hook_views_pre_view(), but still do not get the og_menu block. I have read the previous posts regarding og_menu block visibility in views and understand that the maintainer does not see this as an og_menu issue. OK.

I am looking for other ways to maintain the og_menu block visibility. I began with using the PHP option in the og_menu group block settings. It should always display block if the php code returns TRUE:

$context = og_context(); // Get og context
 
// If there is a value, return TRUE
if ($context) {
  drupal_set_message('There is a group context');
  return TRUE;
}

That didn't work. So, I decided to manually set the group context to a single group and force the block to always load with a that group no matter what:

   $node = node_load(40);
    og_context('node', $node);
    return TRUE;

To my surprise, this didn't work either. So, either there is a bug in the og_menu block or there is some other way this can be achieved other than making sure group context is set. Does anyone know?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rv0’s picture

Category: Bug report » Support request

The first thing og_menu_block_view does is check og_context(), if it is not set, it wont do anything.
hook_views_pre_view should work just fine for setting the context, in fact I'm using this approach on one site on at least 6 views.

Go into the og_menu code, place a dpm(og_context()); (requires devel.module) in og_menu_block_view and see for yourself if a context is set or not...

ps: the if($context) in your code may be not such a good idea.. check for !empty($context) instead.
pps: setting the block visibility has no use here, unless you want to explicitly hide the block in some occasions

SomebodySysop’s picture

Thank you for the suggestion. I tried it and discovered that og_menu_block_view() doesn't execute when I execute the View!

The view is a link in the og_menu block. og_menu_block_view executes correctly when I click on the group node. When I click on the view link within the menu, the hook isn't even touched!

So I altered my hook_views_pre_view code to set group context AND manually run og_menu_block_view():

		$node = node_load(arg(1));
		og_context('node', $node); // Set og context
		og_menu_block_view('og_single_menu_block'); // manually run og_menu block view

The result when I click on the view link: og_menu_block_view() is executed, I get a group context reported back in og_menu_block_view(), but no block is actually rendered (see attached).

My view uses the Group context detection group url format: group/%/content (see attached) and is executed from the group menu in group context. The % is the group node ID.

Is there some setting I have missed? Help!

SomebodySysop’s picture

SomebodySysop’s picture

rv0’s picture

Hm I wasn't aware of any OG Context "group url" setting and a quick google reveals its parts of og_extras.module.
Could you try disabling that module and see if the og menu block shows up? (keeping the pre_view code)

SomebodySysop’s picture

OG Extras module disabled. Same results as before. og menu block does not appear on view. Group context is set, but og_menu_block_view does not execute unless I manually execute it in hook_views_pre_view. Even then, even through group context is enabled, the block still does not appear.

I put in a couple more dpms to display the values for $menu and $block in og_menu_block_view: They are the exact same when the group node link is clicked (and og_menu block appears) and when the view link is clicked (and og_menu block does NOT appear). See latest attachments.

og_menu_block_view view link clicked 2-14-2014 4-25-27 PM.png
og_menu_block_view group node link clicked 2-14-2014 4-25-27 PM.png

I think in this case it is safe to say that the block not appearing has nothing to do with group context not being present?

Again, is there some setting somewhere that I have overlooked? Is it even possible for the og_menu block to be displayed with a view?

SomebodySysop’s picture

I'm sorry -- there was an error in my code that mistakenly displayed $menu data instead of $block data. Attaching corrected images. $block data is the same when og_menu block appears and does not appear in view.

SomebodySysop’s picture

Unable to get a solution as to why the og_menu_block_view will not display on view even when group context is available, I decided to look for another solution.

The simple alternative was to create my own block. I did it programmatic-ally from my module. Then, using Drupal block settings, I set it to ONLY display when my group views are executed.

Not elegant, I know.

The final step was amazingly simple: I generate the block data (the menu itself) using og_menu_block_view() (yes, the same block_view that won't display on the view) in order to display the group menu on a group view. In hook_block_view() in my module, I only need this:

		// display og_menu block

			$block = og_menu_block_view('og_single_menu_block'); // get block code from og_menu block view
			return $block;

So far, it appears to be working. My custom block only appears where I need a group menu the og_menu group menu block won't display.

Why won't the og_menu block won't display on it's own? This is a mystery I hope someone can resolve.

rv0’s picture

Status: Active » Closed (works as designed)

Closing.. Just had another project where I set context via hook_views_pre_view and its working fine
example:

/**
 * Implements hook_views_pre_view().
 */
function MYMODULE_glue_views_pre_view(&$view) {
  if ($view->name == 'project_logo' && $view->current_display == 'block') {
    $gid = arg(1);
    if (!empty($gid) && is_numeric($gid)) {
      $node = node_load(arg(1));
      og_context('node', $node); // Set og context.
    }
  }
}

So this module works as designed