function required_by_role_field_widget_form_alter in Required by role 7
Implements hook_field_widget_form_alter().
File
- ./
required_by_role.module, line 38
Code
function required_by_role_field_widget_form_alter(&$element, &$form_state, $context) {
if (!$context['instance']['required']) {
global $user;
$account = $user;
$settings = $context['instance']['settings'];
// Getting the value based on our rules and some contextual information.
$is_required = required_by_role_is_required($account, $settings, $context, $form_state);
// We dediced to back to search manually the "#required" property.
// Obviously it is not the best solution and it needs work but the option of
// recreate the element was not feasible as it was done because the are
// running into infinite loops in field_default_form and
// field_multiple_value_form as long the hook_field_widget_properties_alter
// is not allowing us to modify the $context property and after is late to
// act on a non "deployed" element.
//
_required_by_role_set_property($element, $is_required, $context, $form_state);
// Give the opportunity to other modules to act on this property.
drupal_alter('required_property', $element, $field, $is_required);
}
}