The drupal core enables add fields to a "profile", without using the module Profile2, like any entity. when the administrator is creating a user account would be really good that the fields shown to depend on the selected role for this new user.
for example:
I have two roles, worker and student.
I have two fields created, workplace and school.
if I select worker should ask me as required field work downtown and do not show the school field, and vice versa.
would be great to have this functionality in this useful module.


peterpoe’s picture

Status: Active » Closed (won't fix)

You can use the Field Permissions module to do this:

reych9’s picture

Status: Closed (won't fix) » Active

You did not understand me I do not think field_permissions solve my problem.
field_permissions hides the fields acording to the role of the active user.
on my site only the administrator can create a new account, and is the administrator who selects what role will have this new account.
the utility I need is that according to the role selected by the administrator for this new account, show or hide the fields to be filled by the administrator.
field_permissions detects who is the manager and showed him all the fields.

peterpoe’s picture

Title: make the user fields can be dependent on the selected user role. » Ability to add dependencies on any form element, not just Field API fields

Sorry, I misread. Conditional Fields only supports Field API fields. If you want to add a dependency for form elements that are not fields, you have to code it. You can write your own code, maybe using the conditional_fields_attach_dependency() function in a custom module, but I think it's currently broken for custom dependencies.

Having an UI for custom dependencies would be nice though.

reych9’s picture

thanks for your prompt replies, I'm not an expert programmer, I'm just a novice, I hope shortly to delve a little deeper into the drupal code.
for now I'm trying to solve the problem by creating a new static field with all the roles, hiding the original roles field and linking them with onclic jabascript event, but I found a new problem, I have just post it,

thank you very much again.

MustangGB’s picture

This was as far as I got before getting stuck.

 * Implements hook_element_info_alter().
 * Adds an #after_build function to all form elements.
function custom_conditional_fields_element_info_alter(&$types) {
  foreach ($types as $type => $info) {
    $types[$type]['#after_build'][] = 'custom_conditional_fields_element_after_build';

function custom_conditional_fields_element_after_build($element, &$form_state) {
  // Ensure that the element is roles.
  if (isset($element['#name']) && $element['#name'] == 'roles') {
    $field = $element;
  else {
    return $element;

  $form = &$form_state['complete form'];

  // Some fields do not have entity type and bundle properties. In this case we
  // try to use the properties from the form. This is not an optimal solution,
  // since in case of fields in entities within entities they might not correspond,
  // and their dependencies will not be loaded.
  if (isset($field['#entity_type'], $field['#bundle'])) {
    $entity_type = $field['#entity_type'];
    $bundle = $field['#bundle'];
  elseif (isset($form['#entity_type'], $form['#bundle'])) {
    $entity_type = $form['#entity_type'];
    $bundle = $form['#bundle'];
  else {
    return $element;

  module_load_include('module', 'conditional_fields');

  $dependee = array(
    '#field_name' => 'roles',
    '#parents' => array('account', 'roles'),

  $dependent = array(
    '#field_name' => 'field_group',
    '#field_parents' => array('field_group', 'und'),

  $options = array(
    'state' => 'visible',
    'condition' => 'value',
    'value' => array(
        4 => 4,
        'value' => 4,
        'target_id' => 4,
    'values' => array(),
    'value_form' => $form_state['values']['roles'],
    'effect' => 'show',
    'effect_options' => array(),
    'element_view' => array(
    'element_view_per_role' => 0,
    'element_view_roles' => array(),
    'element_edit' => array(
    'element_edit_per_role' => 0,
    'element_edit_roles' => array(),
    'selector' => '',
    'grouping' => 'OR',

  conditional_fields_attach_dependency($form, $dependee, $dependent, $options);

  return $element;
liquidcms’s picture

Issue summary: View changes

anyone make any progress on this?