1

I'm loading content from a third party system to Drupal using the Feeds and Data modules. Drupal will be used as an intranet, the users will be able to log in and see their account records (the data I'm getting into Drupal). One of the fields has the user name (not the user id), so in the external system a record can be referenced to each user.

In views is posible use the uid as an argument and show content that references to that uid. Is there a way that I can use the user name as an argument and show the content if that user is logged in or viewing his/her user profile?

Data module does not allow relationships when creating a view.

I suppose I can insert PHP code, use the user name then load de uid, and use de uid as validator in views, I'm not a PHP expert and I'm not sure if that is the correct way to do it.

Thanks in advance for your advices.

1 Answer 1

1

Use the Data name argument to filter the results by. Each content field has it's own argument that you can choose to filter the results by.

(edit: reply to comment) Let's say that your drupal username is user3 with a UID of 3. The user ID of the external data will be user3? So when the user goes to mysite.com/user/3 the argument will be 3 which doesn't help with the external data because that needs to be mapped to user3? If the user ID of the external data is 3 then you can use data: field_userID or whatever it is and get arg(1) using provide default value from PHP code, page manager or Views Arguments from Context. Now, if you to map the Drupal username to the external data username/user ID which is user3 then use provide default value from PHP code, get the global $user variable and use $user->name for the argument. This maps the user's name to the database column in the data table and returns (filters) all results/ database rows with that username in that column.

Don't validate it until you get it working.

global $user;
return $user->name;

or

return arg(1);
3
  • Yes @Adam I'm trying to use the Data field that has the user name, but in views when it comes to validate the argument, I can only validate it with the user id. Manually, if I change the value, for the user id, instead of the user name, the view works. But in this case I can't get the user id from the external system.
    – Arturo
    Commented Jun 17, 2011 at 19:07
  • Thanks @Adam, the view works like a charm with the default value for the argument from PHP code. When I type the argument in views preview it does work and the block shows the records filtered. I thought I would be necessary to validate the argument with the user, but leaving the basic validator does work. You saved me, I imagined I was going to be more difficult. Thanks.
    – Arturo
    Commented Jun 18, 2011 at 22:04
  • I try to simplify things first. Still you should validate the UID in order so the View responds correctly if it isn't correct.
    – Adam S
    Commented Jun 18, 2011 at 23:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.