开发者

Drupal: Showing nodes related to a profile when a cck field of those nodes have the profile nodeid of that user

开发者 https://www.devze.com 2023-04-13 05:47 出处:网络
I need to show all nodes of a specific nodetype, related to the profile node of each user, inside a certain page.

I need to show all nodes of a specific nodetype, related to the profile node of each user, inside a certain page. This is what I have:

  • Users with their userids (example uid A)
  • A Profile node for each user (example nodeid B)
  • Several reg nodes with a cck field that contains the nodeid of the profile node (example cck field C)

I need to show inside a page all reg nodes that have inside that cck field B the nodeid A. For each user. So I enter a page usersregnodes/uidA and see all regnodes that are related to that user because in their cck field C they´ve got the node nodeidB t开发者_高级运维hat´s the profile nodeid of that user.

I´m struggling with relationships and arguments. So far, I think that I should create a relationship Node:Content Profile. The filter should be the reg nodetype. And the argument should be the userid (?). I can´t make this work, because all combinations and try and error that I´ve tried results in blank results.

I would really appreciate your help! THANKS! Rosamunda


You could use a view to get this done. The trick is to change the argument validation.

If I got it right you need to pass the uid as an argument to a view, but get the nodes that reference the nid of content profiles of that particular uid.

To achieve this you need to build a view and set an argument with a custom validator.

Build the view as follows:

  1. It's a node view;
  2. Set up an argument. Choose the node reference field that contains the nid for your argument;
  3. In the argument configuration screen, look for "validator options";
  4. Select "PHP code" instead of "Basic Validation";
  5. Use the following code (don't use php opening and closing tags):

    $prev_arg = $handler->argument;
    $handler->argument = content_profile_load('content_type_name', $prev_arg)->nid;
    return $handler->argument;
    

This way you should be able to change the value of the argument from the uid into the content profile nid and get the results of the view filtered by the nid.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号