You are here

function conditional_fields_field_behaviors in Conditional Fields 7.3

Determine which dependency behaviors should be used in forms and content display, depending on dependency options and user roles.

Parameters

$op: 'view' or 'edit'.

$options: Dependency options.

Return value

An array of behaviors.

2 calls to conditional_fields_field_behaviors()
conditional_fields_entity_view_alter in ./conditional_fields.module
Implements hook_entity_view_alter().
conditional_fields_form_after_build in ./conditional_fields.module
after_build callback for forms with dependencies.

File

./conditional_fields.module, line 1182
Define dependencies between fields based on their states and values.

Code

function conditional_fields_field_behaviors($op, $options) {
  global $user;
  if ($options['element_' . $op . '_per_role']) {
    foreach ($options['element_' . $op . '_roles'] as $rid => $role_behaviors) {
      if (isset($user->roles[$rid])) {
        $behaviors = $role_behaviors;
        break;
      }
    }
  }
  else {
    $behaviors = $options['element_' . $op];
  }

  // Filter out inactive behaviors.
  $behaviors = array_filter($behaviors);
  return $behaviors;
}