terça-feira, 17 de abril de 2012

Configuring Selection List in Drupal to show/hide limited data

Drupal is a powerfull content manager that allow us create content type with custom fields. There is a possibility to define allowed values in a Select List like countries, days, month, etc.

Also there is a possibility to input custom Select List depending on a role of the user. In my case I had to create 3 different roles that can only fill limited data in a Selection List.

In this case we have to input php code in the selection list field. Just go to content type > manager field > selection list field.

Basically we have to set:
global $user; //get user informations

By this you can get the role and the user name by doing this:

$user->roles;
$user->name;



Then you can create a variable of type array to input the custom values that will show depending on the role and name of the user. Finally return this variable to show in the selection list:

return $variable;

Nenhum comentário: