1

I have a view that filter a list of taxonomies based on the taxonomies associated to the logged in user. This works fine. Now, I need to create an exception only for users with role "administrator" that must see the complete list of taxonomies, without any filter applied. I know how to check the logged user role in views, but I can't figure out how to avoid the contextual filter for the specific case.

IMPORTANT NOTE: sorry guys, I forgot to mention that the view will filter the taxonomies list in admin content-type form and not for the front-end pages.

  • You could hack this... Create a second views page with the exact same path, remove the contextual filter, make its access restricted to administrators only and make sure this views page is listed before the other one (reorder displays in the edit view name/description dropdown button). It will load this page for admins, and those who do not have permission will fall back to the second page. – Neograph734 Jun 1 '16 at 8:30
  • @Neograph734 please post that as an answer. – No Sssweat Jun 1 '16 at 8:32
  • @NoSssweat it always felt somewhat wrong, and it does not remove the contextual filter as asked... So I posted as a last resort comment. But I can make it into an answer. – Neograph734 Jun 1 '16 at 8:33
  • @Neograph734 true, but at the end of the day it accomplishes what he wants. Not all answers need to be exactly as asked. Whether the OPer accepts your answer is up to him. – No Sssweat Jun 1 '16 at 8:36
  • 1
    @NoSssweat you are right. Done :) – Neograph734 Jun 1 '16 at 8:37
2

Not entirely an answer to the question, more a workaround, but you could do it as follows.

Make sure to create a second page. It has to be identical to the original one (including the path), so you can clone it from the edit view name/description dropdown button. Then make sure to remove the contextual filter from this display only, and limit the access to users with the administrator role. Finally make sure this views page is listed before the other one (reorder displays in the edit view name/description dropdown button).

This works because views attempts to load the path, if there is no access for the first display, views attempts to load the second display. So all users that have no administrator role will see the second display, while the admins will get the first display without contextual filter.

0

You can use hook_views_query_alter to alter the views query. So that you can use 2 different query for "administrator" role and the other roles.

Refer : https://api.drupal.org/api/views/views.api.php/function/hook_views_query_alter/7.x-3.x

0

Thanks a lot to all for the answers! I think I've found a good solution to my specific problem by following this discussion Using the Views PHP module I can set basic or even complex php controls on a contextual filter in the view.

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.