Advertisement
Guest User

Untitled

a guest
May 23rd, 2012
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.63 KB | None | 0 0
  1. function usersfilter_form_alter(&$form, &$form_state, $form_id) {
  2.      global $user;
  3.      if (in_array('administrator', array_values($user->roles))){
  4.         return; //administrator
  5.      }
  6.      
  7.     $newUsers = array();
  8.     $existingUsers = $form['field_assign_to']['und']['#options'];
  9.    
  10.     foreach ($existingUsers as &$existingUser) {
  11.         if($existingUser == $user->name){
  12.             $newUsers[] = $existingUser;
  13.             continue;
  14.         }
  15.        
  16.         $account = user_load_by_name($existingUser);
  17.        
  18.         if (user_access('access administration pages',  $account)) {
  19.             $newUsers[] = $existingUser;
  20.             continue;
  21.         }
  22.     }
  23.    
  24.     $form['field_assign_to']['und']['#options'] = $newUsers;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement