0

I made a view, with a contextual filter in the user id. The fields are:

  • Name

  • uid

  • Email.

    [ { "username": "pruthiswebar", "id": "8" } ]

If I am logged, I can see the email, if I go to anonymous user, I can´t. There is not a permission for "show user email" or something? How can I configure this?

9
  • The anonymous User does not have an email address. So you are not able to see the email address. Probably I do not understand your question. What do you want to do? And where in the process?
    – btemperli
    Mar 28, 2018 at 6:32
  • i want to show authenticated users.
    – ValRob
    Mar 28, 2018 at 20:03
  • To whom? To everybody who is calling the REST-service?
    – btemperli
    Mar 28, 2018 at 22:10
  • I think there is no permission to show user data to anonymous user. Normally the user data (except id and username) is only visible to the user itself or user with admin permission.
    – btemperli
    Mar 28, 2018 at 22:13
  • @btemperli yes... to everybody
    – ValRob
    Mar 29, 2018 at 14:18

1 Answer 1

1

To add informations to the view, which are not displaying of whatever reasons - you can hook into the view and "print" the informations manually.

Step 1 Create a custom module (https://www.drupal.org/docs/8/creating-custom-modules) I'm not sure, but probably you can add the preprocess in the MYTHEME.theme-File. Then you do not need your own module for this.

Step 2 Add the preprocess hook (https://api.drupal.org/api/drupal/core%21modules%21views%21views.theme.inc/function/template_preprocess_views_view/8.5.x)

MYMODULE_preprocess_view(&$variables) {
    // Todo: check if the view is the view you want to add the user email.
    $user_id = 1; // Change for other users.
    $user = Drupal::entityTypeManager()->getStorage('user')->load($user_id);
    $variables['users'][$user_id] = $user;
}

Step 3 In the twig-template of the view you can add the userdata (https://api.drupal.org/api/drupal/core%21modules%21views%21views.theme.inc/group/views_templates/8.5.x)

{{ dump(users) }}     {# for the user array. #}
{{ dump(users[1]) }}  {# for the user with the id 1 #}

Your Answer

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

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