I am using Panel's build-in user/%user page to override the user profile page.
The problem is that drupal's core trigger module and rules module not recognize visits of this pages as visit of user page. There is no problem when I disable overrided panel page.

For example if I visit the panel page http://mysite/user/5 both modules not triggering action on event "User page has been viewed".
If I visit the same http://mysite/user/5 page when panel page is disabled both modules trigger action.

I don't know if it issue for Panels module or for rules and trigger modules. I have opened a bug report also for Rules module #591882: Rules doesn't trigger action when the user page is overridden ,but no answers there.

CommentFileSizeAuthor
#11 ctools_user_view_trigger.patch546 bytesfrankcarey
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

artscoop’s picture

Version: 6.x-3.0 » 6.x-3.x-dev

Hi,
Same problem here.
However it works well on overridden nodes.
I don't know much but I'll investigate.

merlinofchaos’s picture

Status: Active » Closed (won't fix)

A quick piece of investigation shows that trigger.module works on hook_user() (I assume rules does as well) which means it will only get triggered if you have the user profile pane. I don't think there's much that can really be done to fix it so this pane is not necessary.

dima700’s picture

A small module with implementation of hook_ctools_render_alter and hook_rules_event_info did for me the job.

artscoop’s picture

Hi merlinofchaos,
You're right, I had no time to talk about it here but yes, it works with the User Profile pane.
dima700, can you tell me more about this ?

dima700’s picture

mani.atico added here http://drupal.org/node/543012 a small module that adds a "Node panel page been viewed" event to rules module.
I have edited his code to add "User panel page been viewed" event.
This is a module code:

my_ctools_rules.info

; $Id$
name = "My CTools Rules"
description = "Panels user page is going to be viewed event."
core = 6.x
package = Chaos tool suite
dependencies[] = ctools
dependencies[] = rules

my_ctools_rules.rules.inc

<?php
// $Id:

/**
 * Implementation of hook_rules_event_info().
 */
function my_ctools_rules_rules_event_info() {
  return array(
    'users_overrided_panel_page_view' => array(
      'label' => t('Overrided user Panel Page is viewed by acting user'),
      'module' => 'CTools',
      'arguments' => my_ctools_rules_events_arguments(t('user been viewed'),t('acting user')),
  ));
}

/**
 * Returns the argument definition for user been viewed and the acting user (global $user)
 */
function my_ctools_rules_events_arguments($user_been_vievew_label,$acting_user_label) {
  $args = array(
    'user_been_vievew' => array(
      'type' => 'user',
      'label' => $user_been_vievew_label,
    ),
	'acting_user' => array(
      'type' => 'user',
      'label' => $acting_user_label,
    ),
    
  );
  return $args;
}

my_ctools_rules.module

<?php

/**
 * @file Rules integration for ctools module
 *
 * Invokes event where a user viewed other users overrided panel page
 * 
 */

function my_ctools_rules_ctools_render_alter($info, $page, $args, $contexts, $task, $subtask) {
  if (isset($contexts['argument_uid_1']) &&
  $contexts['argument_uid_1']->type == 'user') {
	global $user;  
    $user_been_viewed = $contexts['argument_uid_1']->data;
	
	if (($user->uid != $user_been_viewed->uid) AND ($user->uid != 0) ) { //invoke only when acting user is not user being viewed and not anonymous user
    rules_invoke_event('users_overrided_panel_page_view', array('user_been_vievew' => &$user_been_viewed, 'acting_user' => &$user));
	}
  }
}

I am not programmer. It works for me but I will appreciate if somebody can check the my_ctools_rules_ctools_render_alter function.

frankcarey’s picture

seems fine, but why create a new rules event, why not just have it trigger the existing "User page has been viewed" event?

Also, is it possible to just invoke the "View" op in hook_user manually so any module using that would work? I'll try that and see if it gets anywhere.

frankcarey’s picture

Title: Event "User page has been viewed" not triggered when using overrided Panel page » user "view" hook not being called
Status: Closed (won't fix) » Needs review

Yes, this seems to work fine. @merlin is there anything bad in just doing it this way? If not, would the next step of patching ctools itself make sense?

function my_module_ctools_render_alter($info, $page, $args, $contexts, $task, $subtask) {
  if (isset($contexts['argument_uid_1'])) {
    $user = $contexts['argument_uid_1']->data;
    module_invoke_all('user', 'view', array(), $user);
  }
}
frankcarey’s picture

Title: user "view" hook not being called » Event "User page has been viewed" not triggered when using overrided Panel page, user "view" hook not being called
merlinofchaos’s picture

Status: Needs review » Fixed

You should possibly do some checking on the path to make sure that it's really a page you want to mark the user as being viewed, in case you ever create new pages. For example, user/%user/tracker (should you do that through Panels) might trigger this code but would not count as viewing the user. Otherwise it seems fine to me.

frankcarey’s picture

Status: Needs review » Fixed

@merlin, thanks. I tested with the user/%user/contact page that comes with ctools, and you are right. It does fire the "view" operation when it "shouldn't". From my initial look, user.module doesn't do anything fancy here. It just uses hook_menu to set user_view() as the page callback.

Here is the progression from there
user_view($account) --> user_build_content($account) --> user_module_invoke('view', $edit, $account)

Ctools overrides the page handler and sets it's own, with a fallback to user_view(). I'm testing out adding the code below (new) in ctools/page_manager/plugins/tasks/user_view.inc so that if the fallback isn't used, the core user op will still run.

/**
 * Entry point for our overridden user view.
 *
 * This function asks its assigned handlers who, if anyone, would like
 * to run with it. If no one does, it passes through to Drupal core's
 * user view, which is user_page_view().
 */
function page_manager_user_view($account) {
  // Load my task plugin:
  $task = page_manager_get_task('user_view');

  // Load the account into a context.
  ctools_include('context');
  ctools_include('context-task-handler');
  $contexts = ctools_context_handler_get_task_contexts($task, '', array($account));

  $output = ctools_context_handler_render($task, '', $contexts, array($account->uid));
  if ($output === FALSE) {
    // Fall back!
    module_load_include('inc', 'user', 'user.pages');
    $output = user_view($account);
  }
  //---------new---------->
  else {
    //fire off "view" op so that triggers still work
   module_invoke_all('user', 'view', array(), $account);
  }
  //---------new---------->
  return $output;
}
frankcarey’s picture

Status: Fixed » Needs review
FileSize
546 bytes

yeah, that seems to work well now. Patched against 3.1

frankcarey’s picture

FYI: user_module_invoke('view', array(), $account); didn't work because of pass-by-reference issues, so I returned to the module_invoke_all
() call in the patch. I'll edit the code above to reflect that change.

frankcarey’s picture

Status: Fixed » Needs review

http://drupal.org/node/305289#comment-2201196

Working correctly for activelyOUT, who is using spaces and context

frankcarey’s picture

Status: Needs review » Reviewed & tested by the community
sdboyer’s picture

Project: Panels » Chaos Tool Suite (ctools)
Version: 6.x-3.x-dev » 6.x-1.x-dev
Component: Panel pages » Code

Moving to the CTools, where this properly belongs. This won't cover all cases where the user should be marked as viewed (as some of the approaches in the other comments might), but it will at least mirror core functionality.

Committed.

merlinofchaos’s picture

Status: Reviewed & tested by the community » Fixed

Whoops, sdboyer forgot to set fixed when he committed this.

BenK’s picture

Just need to keep track of this thread for reference....

Status: Fixed » Closed (fixed)

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