You are here

function multiple_registration_field_widget_form_alter in Multiple Registration 7

Same name and namespace in other branches
  1. 8.2 multiple_registration.module \multiple_registration_field_widget_form_alter()
  2. 8 multiple_registration.module \multiple_registration_field_widget_form_alter()
  3. 3.x multiple_registration.module \multiple_registration_field_widget_form_alter()

Implements hook_field_widget_form_alter().

File

./multiple_registration.module, line 507
Add ability to create several registration pages.

Code

function multiple_registration_field_widget_form_alter(&$element, &$form_state, $context) {
  $instance = isset($context['instance']) ? $context['instance'] : array();
  if (!empty($instance['settings']['user_additional_register_form'])) {

    // If nothing was selected.
    if (max($instance['settings']['user_additional_register_form']) === 0) {
      return;
    }
    $element['#access'] = multiple_registration_is_field_accessible($instance);
    if (!$element['#access']) {

      // Disable required property for the field if access is disabled.
      variable_set('is_current_field_accessible', FALSE);
      $element['value']['#required'] = FALSE;
    }

    // Mark field as required for special role regarding field configuration.
    if ($element['#access'] && isset($instance['settings']['user_additional_register_form_required'])) {
      $field_required_for = $instance['settings']['user_additional_register_form_required'];

      // Where arg(index) is a parsed current url index.
      if (arg(1) === 'signup') {
        if (in_array(arg(2), $field_required_for, TRUE)) {
          $element['value']['#required'] = TRUE;
          $element['#required'] = TRUE;
        }
      }
    }
  }
}