3

I created a content type coty1.

I have 2 user roles that can create that content type. role1 and role2.

1.How can I create view that one of the filter field is expose that allow me to choose just users that have role1 or role2 (not all the users of the site).

2.How can I create view that one of the filter field is expose that I can choose just users that realy created one or more from coty1 content type?

Thanks a lot.

1 Answer 1

1

You need some custom code in order to do something like this.

You can put #access on any form element, and along with hook_form_alter you are able to alter the views exposed form and require a permission that the two roles have, making it so that only users with those roles can see and use the exposed filter.

The same technique can be used for the 2nd field you want alter.

In code this could look something like this:

module_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'foo') {
    $form['exposed_filter_1']['#access'] = user_permission('special permission role 1 and 2 have');
  }
}

This is example code. You need to find out the form id, and maybe do other checks. Also You need to do a SQL query to figure out if the user has created a node of that type.

2
  • Thanks, but I want that all users with all roles can see and use the exposed filter. But the exposed filter will show just users that have specific role.
    – Jaja
    Jan 16, 2012 at 10:54
  • That can be done with hook_form_alter as well, but you would need to set the #options instead. Alternative you would need to create a custom views handler which would give you more fine tuned control.
    – googletorp
    Jan 16, 2012 at 11:36

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.