I figured out the rules I needed to get the redirect to happen. Just go to rules->import to load the rule. I may have to be modified if you want node types other that "profile". One trick was that I was getting an redirect loop because i have panels 3 installed, and I guess it registered "viewing content" for the node, even though it was a user page, not a node page, so I set an additional condition that arg(0) != "user.

With some more thought around this, I'd like to see it become a rule supplied by the content_profile module.


array (
  'rules' => 
  array (
    'rules_2' => 
    array (
      '#type' => 'rule',
      '#set' => 'event_node_view',
      '#label' => 'Redirect to user profile, when viewing profile node',
      '#active' => 1,
      '#weight' => '0',
      '#categories' => 
      array (
        0 => 'content_profile',
      ),
      '#status' => 'custom',
      '#conditions' => 
      array (
        0 => 
        array (
          0 => 
          array (
            '#weight' => 0,
            '#info' => 
            array (
              'label' => 'Viewed content is Profile',
              'arguments' => 
              array (
                'node' => 
                array (
                  'type' => 'node',
                  'label' => 'Content',
                ),
              ),
              'module' => 'Node',
            ),
            '#name' => 'rules_condition_content_is_type',
            '#settings' => 
            array (
              'type' => 
              array (
                'profile' => 'profile',
              ),
              '#argument map' => 
              array (
                'node' => 'node',
              ),
            ),
            '#type' => 'condition',
          ),
          '#type' => 'AND',
          '#weight' => 0,
          1 => 
          array (
            '#weight' => 0,
            '#info' => 
            array (
              'label' => 'Not viewing user account page',
              'label callback' => false,
              'module' => 'PHP',
              'eval input' => 
              array (
                0 => 'code',
              ),
            ),
            '#name' => 'rules_condition_custom_php',
            '#settings' => 
            array (
              'code' => 'return arg(0) != "user";',
              'vars' => 
              array (
              ),
            ),
            '#type' => 'condition',
          ),
        ),
      ),
      '#actions' => 
      array (
        1 => 
        array (
          '#weight' => -10,
          '#info' => 
          array (
            'label' => 'Redirect to User Account Page',
            'label callback' => false,
            'module' => 'System',
            'eval input' => 
            array (
              0 => 'path',
              1 => 'query',
              2 => 'fragment',
            ),
          ),
          '#name' => 'rules_action_drupal_goto',
          '#settings' => 
          array (
            'path' => 'user/[author:uid]',
            'query' => '',
            'fragment' => '',
            'force' => 1,
            'immediate' => 0,
            '#eval input' => 
            array (
              'token_rules_input_evaluator' => 
              array (
                'path' => 
                array (
                  0 => 'author',
                ),
              ),
            ),
          ),
          '#type' => 'action',
        ),
      ),
      '#version' => 6003,
    ),
  ),
)

Comments

Tamela’s picture

I tried to import this into Rules and kept getting "Import Failed" Any suggestions?

Bilmar’s picture

I was able to import the rule without a problem.
Make sure to not include the starting <?php and the ending ? > when pasting the code into rules import

Rosamunda’s picture

I´ve successfully imported the rule, but it just won´t work...
I mean, I click on the node, that´s checked as a content profile, and it won´t redirect...
Yes, the rule is active... don´t know why isn´t working, the rule seems correct.
Any thoughts on this will be very much appreciated.
Thanks!
Rosamunda


Update:

doh! My content probile wasn´t "Profile". After that change it works like a charm.
THANKS!!

Rosamunda’s picture

Ok, I´ve got this rule working BUT, I can´t get out that page when I try to go to the homepage...
Pretty weird, does this happened to anyone?

intent’s picture

Very cool, thanks for sharing.

One thing - if I go to the node/nid/edit page, the redirect doesn't work. Looking at the rule it seems like it should work. Anyone have any ideas?

* Edited to add: I tried adding another condition return arg(2) == 'edit'; but that didn't work either.

Tamela’s picture

I think I'm confused about what this does. You are trying to redirect people away from the content profile to their user account? I think I'm trying to do the opposite. I want the author link from a posted node to link to the content profile instead of their user account. I have little links all over my site - author links under comments, the list of who's new, who's online etc. All of them link back to the user account and not to my beautiful profiles created with Content Profile.

I thought that's what this rule was set up to do, but when I implemented it I could no longer access my Content Profiles. The author links and others didn't redirect. So I'm guessing I misunderstood.

Does anyone know how to do what I want to do? Any help would be appreciated.
:-)
Tamela

Bilmar’s picture

Yes, this rule is to redirect people to the User Profile page (away from the content profile node). This was useful in my case as I am not using the content profile nodes and rather using a View to override the User Profile url and showing the user's full profile at this page. Regards

Rosamunda’s picture

Ok, besides the error I´ve found in #4 (wich could be my mistake since nobody else seems to have the same problem), I think the idea of redirecting someone to their user profile is better than to have their user profile in one place and then make people go to their content profile node.
I mean, could this be confusing to the user?

frankcarey’s picture

@Tamela - most of us are probably using Panels or Views or some other means to have the content_profile show up in place of the normal user profile when you go to user/N. I would think you'd want to do the same since you then don't have to modify any of the link that point people to the user page.

frankcarey’s picture

also, it shouldn't be hard to just include this rule in the content_profile module, then people can modify it for their own needs.

avolve’s picture

I imported this (after getting stuck trying to create my own rule)

Redirect does not occur, and I receive the following message in the log

An error occured during rule evaluation. It follows the evaluation log:
0 ms "Content is going to be viewed" has been invoked.
0.085 ms Executing the rule "Redirect to user profile, when viewing profile node XX" on rule set "Content is going to be viewed"
0.281 ms Condition "Viewed content is Profile" evaluated to TRUE.
0.396 ms Unable to find "condition" of name "rules_condition_custom_php" with the label "Not viewing user account page". Perhaps the according module has been deactivated.
0.433 ms Condition "Not viewing user account page" evaluated to FALSE.
0.481 ms Evaluation of "Content is going to be viewed" has been finished.

Anyone able to advise a solution?

---

+1 for this being an option to include in the final module

nehalmehta’s picture

I am getting same error. If anyone finds solution for this.. Please let us know.

greta_drupal’s picture

Likewise, I wish my user/author links to redirect to Content Profile rather than user page. And, I am using Views. How are you using Views for the redirect?

[I tried core action/trigger, but the redirect did not redirect. I am using a theme that embeds the login within the template file, displaying it on homepage. This might be the reason core action/trigger isn't working.]

kevinwalsh’s picture

Thanks for this! i was getting the redirect loop as well, due to Panels.

yesct’s picture

I imported this and then I edited the first condition to refer to the personal information content type (that's my content profile node type name instead of 'profile'). OK, but then

I am also getting:

An error occured during rule evaluation. It follows the evaluation log:

* 0 ms "Content is going to be viewed" has been invoked.
* 0.087 ms Executing the rule "Redirect to user profile, when viewing profile node" on rule set "Content is going to be viewed"
* 0.263 ms Condition "Viewed content is Personal Information" evaluated to TRUE.
* 0.355 ms Unable to find "condition" of name "rules_condition_custom_php" with the label "Not viewing user account page". Perhaps the according module has been deactivated.
* 0.386 ms Condition "Not viewing user account page" evaluated to FALSE.
* 0.436 ms Evaluation of "Content is going to be viewed" has been finished.

yesct’s picture

I got the error to go away and the rule to work by going to the module page and enabling the php input filter module. Note I did NOT check any boxes to give any roles permission to use the filter.

does anyone see a problem with security with having the module enabled?

yesct’s picture

Now, it is a bit strange, on the /user/nid page, to have a "view" link for the content profile node there, because it just redirects back to the page being viewed: /user/nid. What would be the "right" way to hide that view link in the user profile?

tab tamer briefly jumped to mind, but that would (I think) be for all node views, not just the view tab on a particular node type.

firebug shows:

<div class="content-profile-display" id="content-profile-display-personalinformation">
      <ul class="tabs content-profile">
                        <li><a href="/content/dawn">View</a></li>

                         <li><a href="/user/9/edit/personalinformation?destination=user%2F9">Edit</a></li>
                  </ul>
        <div id="node-50" class="node node-type-personalinformation"><div class="node-inner">

so I dont see a way to use css to hide the View link... but I'm no expert themer!

yesct’s picture

I used the devel module, devel themer module and found the view link is printed out because of: site/all/modules/content_profile/content_profile-display-view.tpl.php

<?php if (isset($title)): ?>
  <h3 class="content-profile-title" id="content-profile-title-<?php print $type; ?>">
  <?php print $title; ?>
  </h3>
<?php endif; ?>
<div class="content-profile-display" id="content-profile-display-<?php print $type; ?>">
  <?php if (isset($tabs)) : ?>
    <ul class="tabs content-profile">
      <?php foreach ($tabs as $tab) : ?>
        <?php if ($tab): ?>
          <li><?php print $tab; ?></li>
        <?php endif; ?>
      <?php endforeach; ?>
    </ul>
  <?php endif; ?>
  <?php if (isset($node->nid) && isset($content)): ?>
    <?php print $content ?>
  <?php endif; ?>
</div>

but that seems to just print out "all" of the tabs, not specifically the view tab.

I know this is starting to sound off topic, and well... it might be, but to me, this is part of the solution to the redirect. I'm not sure what issue queue to put a theme question like this in. Please let me know, and I'll open up a new issue there and put a link to that new issue from here.

Thanks!

yesct’s picture

well, is there a better way than:

<?php if (isset($title)): ?>
  <h3 class="content-profile-title" id="content-profile-title-<?php print $type; ?>">
  <?php print $title; ?>
  </h3>
<?php endif; ?>
<div class="content-profile-display" id="content-profile-display-<?php print $type; ?>">
  <?php if (isset($tabs)) : ?>
    <ul class="tabs content-profile">
      <?php foreach ($tabs as $tab) : ?>
        <?php if ($tab): ?>
        <?php if (strstr($tab,'>View</a></span>')): ?>
          <li><?php print '<span id="thmr_10" class="thmr_call"> View</span>'; ?></li>
        <?php else: ?>
          <li><?php print $tab; ?></li>
        <?php endif; ?>
        <?php endif; ?>
      <?php endforeach; ?>
    </ul>
  <?php endif; ?>

yesct’s picture

opps. the spans are because I had the devel module on (I think).

    <?php if (strstr($tab,'>View</a>')): ?>
          <li><?php print ' View'; ?></li>
 

Well, or view source and see whatever your theme is using when it prints out

avolve’s picture

Here is what I am using, rather than rules given the above issue(s).

This snippet is inserted into my themes node-profile.tpl.php, above the other elements

<?php
if (arg(0) == "node") { 
  drupal_goto("user/$node->uid", NULL, NULL, 301);
}
?>

I have taken the comment out of above as it produced some funny results. The comments were

We don't ever want to go to the CCK Profile page itself. Always redirect to the user page.
taken from http://groups.drupal.org/node/14319
frankcarey’s picture

Maintainers: any interest in including this in the content_profile module?

darrellhq’s picture

I would like to see this included in the module. For redirecting a user to the content profile node or the other way around depending upon the preference set on the configuration page.

jumpfightgo’s picture

Status: Needs work » Closed (duplicate)

I just created a patch that achieves this here: http://drupal.org/node/661572#comment-2663766

It uses preprocess_page instead of rules, but seems to achieve the same goal.

kevinwalsh’s picture

I was using this for awhile until i realized it was redirecting people from a page of search results to

So for example:

1. The user profile page built in panels shows a content profile node with comments, with comment containing "foo".

2. A user searches for "foo".

3. First two pages of search results are fine, but third page containing the comment redirects to that user's page.

Disabling this rule disabled the redirection.

-kev

odizle’s picture

Thanks, works for me.