0

The profile owner (currently logged in) sees this (contextual filtered Views block):
enter image description here

CURRENTLY, the other logged in users who visit test_user2's profile page see this:
enter image description here

What I want to achieve, is for the other logged in users who visit test_user2's profile page to see this:
enter image description here

In other words, I want only the account/profile owner to see the Edit field (/user/[nid]/edit) on their own page and to be able to edit his/her profile info. How to do this?

1
  • user contextual filter of user id and select value user uid get from loggin user – Adi Jan 21 '16 at 5:31
1

Create the block without the edit link. Then implement function hook_views_pre_render in your theme.

This hook is called right before the render process. The query has been executed, and the pre_render() phase has already happened for handlers, so all data should be available.

Adding output to the view can be accomplished by placing text on $view->attachment_before and $view->attachment_after. Altering the content can be achieved by editing the items of $view->result.

This hook can be utilized by themes.

Within this you do a conditional check to see if currently logged in is the same as profile owner, then if so add the link to $view->attachment_before

I think you would get quite a lot of answers on this question as there are so many ways to do it.

If you want to do it without coding I think you might get it right with Views arguments in filters installed. You create the link field in an attachment to the block using the currently logged in user as contextual filter, then (via installed module referenced) do the conditional check in your filters section of views on this attachment.

3
  • I am trying the second method (easier without code) for now. I got up to the module installing part. Where on the page do I download the module? Their module page doesn't look like a normal module page. Cheers. – p Ng Jan 21 '16 at 7:42
  • You have to use GIT. Click on version control tab then follow instructions. Google how to install GIT for your platform. Once installed you open a console in your modules directory and issue git comands. – J. Reynolds Jan 21 '16 at 11:05
  • Got it working perfectly using the hook. Thanks for this. – p Ng Jan 22 '16 at 6:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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