1

I want to create a view block that shows all published nodes of a certain content type. I've included an image below.

enter image description here

However the trick here is to only show the link Print Report if the logged in user is the author of that node. So if you look at my image above, the user Dennis Bonilla should be able to see his Print Report link but not see one for the row below for Test McTest.

Is there a module that can help me do this or some administrative trickery in the views ui? Or maybe even programmatically?

0

This is possible via views UI itself.

  • Create a view with content types you need as a filter criteria

  • Then add a "relationship" for "Content: Author". Now add a "contextual filter" for the field "user: uid" with a default argument for "user-id of logged in user" to filter the view.

    enter image description here

    enter image description here

    • Now you will get the list of nodes authored by current logged in user.

    • To get the Print Report Link you could make use of Views PHP module and by adding content:nid field

To List all nodes and Add print report link to only contents of the current user

  • Add a Content: Author UID and a Global: PHP field

  • In global:PHP field, add conditions like below:

    global $user; 
    if ($user->uid ==  $row->uid) {
      echo 'print reports';
    }
    
  • 2
    This will filtered out the logged in user's content But QA want to display all the contents but the print report link with only his contents. – Sumit Madan Nov 10 '14 at 6:53
  • Oh sry I missed it. I will update my answer – Pravin Ajaaz Nov 10 '14 at 7:18
0

The answer of @Pravin Ajaaz is correct but I'd have to disagree of using PHP Views don't use this module .. its bad!

alternatively write you PHP code in the server side ,, and that's possible by writing the result of that field which is well documented here:

Theming a single field in a Views 3 template

0

Two modules can help you do that. Note that you'll likely choose one of these two modules. they aren't dependent on each other. They can both help you get what you want in different ways.

  1. Views PHP
  2. Computed Field

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.