You are here

function registration_field_instance_settings_form in Entity Registration 8

Same name and namespace in other branches
  1. 8.2 includes/registration.field.inc \registration_field_instance_settings_form()
  2. 7.2 includes/registration.field.inc \registration_field_instance_settings_form()
  3. 7 includes/registration.field.inc \registration_field_instance_settings_form()

Implements hook_field_instance_settings_form().

Add default registration field instance settings.

File

includes/registration.field.inc, line 56
Field hooks.

Code

function registration_field_instance_settings_form($field, $instance) {
  $form = $form_state = array();
  $default_settings = isset($instance['settings']['default_registration_settings']) ? $instance['settings']['default_registration_settings'] : array();
  $form['register_tab'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable Register Tab'),
    '#default_value' => isset($default_settings['register_tab']) ? $default_settings['register_tab'] : TRUE,
    '#required' => FALSE,
    '#description' => t('Enable a tab on the content displaying the registration form.'),
  );

  // Flatten scheduling and reminder settings since this form is in tree mode.
  foreach ($default_settings as $key => $val) {
    if ($key != 'settings' and is_array($val)) {
      foreach ($val as $key1 => $val1) {
        if (is_array($val1)) {
          foreach ($val1 as $key2 => $val2) {
            $default_settings[$key2] = $val2;
          }
        }
        else {
          $default_settings[$key1] = $val1;
        }
      }
      unset($default_settings[$key]);
    }
  }
  $settings_form = registration_entity_settings_form($form, $form_state, $default_settings);
  $form['default_registration_settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('Default Registration settings'),
    '#collapsible' => TRUE,
    '#description' => t('These settings will be applied when an entity with this field is saved and does not yet have it\'s own settings applied.'),
  );

  // Unset the save button just in case.
  unset($settings_form['save']);
  $form['default_registration_settings'] += $settings_form;

  // @todo: validation
  return $form;
}