Show / hide Drupal fields

I would like to show / hide certain fields in my Drupal view according to user role.

Provided that I can only have this idea for work, how can I achieve this programmatically or some parameters that I don’t know about in Drupal.

P / S: I know the settings for accessing the basic settings in the view, but this would limit access to the whole view, and not to the field level.

+3
source share
5 answers

You can create two identical Displays (in the same view) and override the field settings and access parameters in each of them. For example, the first display shows the fields that you want to see only a specific role, and set this role for the access control parameter. On the second display, delete unnecessary fields and set access control to the corresponding role.

Start by creating the most restrictive display first and then the least restrictive.

+6
source

I liked this answer, but in my case the field depends on the argument, and I will need to create a new display for each argument (which is impractical).

I installed the Views Custom Field module and used this code for the field:

<?php
if(user_access("some permission string here"))
{
  print "Your field value here";
}
?>
+2

"", , _.tpl.php, :

print $output;

:

if (user_access('administer nodes')) {
    print $output;
}

, .

+2

,

+1

If your fields that you want to exclude, 1) are created using CCK and 2) should be hidden from users of this role everywhere on the site (and not just in this particular view), then you can simply set permissions for the fields so that users don’t can view them. If the current user does not have permissions to view the field that is part of the view, this field will not be displayed to the user.

0
source

Source: https://habr.com/ru/post/1743127/


All Articles