function registration_entity_settings_form in Entity Registration 8.2
Same name and namespace in other branches
- 8 includes/registration.forms.inc \registration_entity_settings_form()
- 7.2 includes/registration.forms.inc \registration_entity_settings_form()
- 7 includes/registration.forms.inc \registration_entity_settings_form()
Return a form for an entity's registration settings.
_state
Parameters
array $form:
object $entity_type:
object $entity:
Return value
array $form
See also
hook_registration_entity_settings()
1 call to registration_entity_settings_form()
- registration_field_instance_settings_form in includes/
registration.field.inc - Implements hook_field_instance_settings_form().
1 string reference to 'registration_entity_settings_form'
- registration_entity_settings_page in ./
registration.module - Page callback for entity registration settings.
File
- includes/
registration.forms.inc, line 527 - Form definitions and callbacks for Registration.
Code
function registration_entity_settings_form($form, &$form_state, $settings, $entity_type = NULL, $entity_id = NULL) {
if ($entity_id) {
// We'll need this info when we submit the form:
$form_state['entity'] = array(
'entity_id' => $entity_id,
'entity_type' => $entity_type,
);
}
// Check to see if date_popup is installed so we can provide a friendlier UI.
$date_popup_installed = FALSE;
if (\Drupal::moduleHandler()
->moduleExists('date_popup')) {
$date_popup_installed = TRUE;
}
$form['status'] = array(
'#type' => 'checkbox',
'#title' => t('Enable'),
'#description' => t('Check to enable registrations.'),
'#default_value' => isset($settings['status']) ? $settings['status'] : -1,
);
$form['capacity'] = array(
'#type' => 'textfield',
'#title' => t('Capacity'),
'#description' => t('The maximum number of registrants. Leave at 0 for no limit.'),
'#size' => 5,
'#maxlength' => 10,
'#required' => TRUE,
'#default_value' => isset($settings['capacity']) ? $settings['capacity'] : 0,
);
$form['scheduling'] = array(
'#type' => 'fieldset',
'#title' => t('Scheduling'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#tree' => TRUE,
);
$form['scheduling']['open'] = array(
'#type' => 'textfield',
'#title' => t('Open Date'),
'#maxlength' => 25,
'#description' => t('When to automatically open registrations. Format: %time. The date format is YYYY-MM-DD and %timezone is the time zone offset from UTC. Leave blank to disable.', array(
'%time' => !empty($settings['open']) ? date_format(date_create($settings['open']), 'Y-m-d H:i:s O') : format_date(time(), 'custom', 'Y-m-d H:i:s O'),
'%timezone' => !empty($settings['open']) ? date_format(date_create($settings['open']), 'O') : format_date(time(), 'custom', 'O'),
)),
'#default_value' => !empty($settings['open']) ? $settings['open'] : '',
'#weight' => 0,
);
if ($date_popup_installed) {
$form['scheduling']['open']['#type'] = 'date_popup';
$form['scheduling']['open']['#date_format'] = 'Y-m-d H:i:s O';
$form['scheduling']['open']['#description'] = t('When to automatically open registrations. (This uses the !timezone.)', array(
'!timezone' => \Drupal::l(t('site default time zone'), \Drupal\Core\Url::fromRoute('system.regional_settings')),
));
unset($form['scheduling']['open']['#maxlength']);
}
$form['scheduling']['close'] = array(
'#type' => 'textfield',
'#title' => t('Close Date'),
'#maxlength' => 25,
'#description' => t('When to automatically close registrations. Format: %time. The date format is YYYY-MM-DD and %timezone is the time zone offset from UTC. Leave blank to disable.', array(
'%time' => !empty($settings['close']) ? date_format(date_create($settings['close']), 'Y-m-d H:i:s O') : format_date(time(), 'custom', 'Y-m-d H:i:s O'),
'%timezone' => !empty($settings['close']) ? date_format(date_create($settings['close']), 'O') : format_date(time(), 'custom', 'O'),
)),
'#default_value' => !empty($settings['close']) ? $settings['close'] : '',
'#weight' => 2,
);
if ($date_popup_installed) {
$form['scheduling']['close']['#type'] = 'date_popup';
$form['scheduling']['close']['#date_format'] = 'Y-m-d H:i:s O';
$form['scheduling']['close']['#description'] = t('When to automatically close registrations.. (This uses the !timezone.)', array(
'!timezone' => \Drupal::l(t('site default time zone'), \Drupal\Core\Url::fromRoute('system.regional_settings')),
));
unset($form['scheduling']['close']['#maxlength']);
}
// Allow for setting open and close date based on tokens:
if (\Drupal::moduleHandler()
->moduleExists('token')) {
$date_fields = array(
array(
'name' => 'open',
'label' => 'Open Date',
'set' => 'scheduling',
),
array(
'name' => 'close',
'label' => 'Close Date',
'set' => 'scheduling',
),
);
foreach ($date_fields as $field) {
$base_weight = isset($form[$field['set']][$field['name']]['#weight']) ? $form[$field['set']][$field['name']]['#weight'] : 0;
$form[$field['set']][$field['name'] . '_use_token'] = array(
'#type' => 'checkbox',
'#title' => t('Use a token to set the @label.', array(
'@label' => $field['label'],
)),
'#default_value' => isset($settings['settings'][$field['name'] . '_date_token']) ? TRUE : FALSE,
'#weight' => $base_weight - 0.5,
);
$form[$field['set']][$field['name'] . '_field'] = array(
'#type' => 'textfield',
'#title' => t('@label Source', array(
'@label' => $field['label'],
)),
'#description' => $form[$field['set']][$field['name']]['#description'] . t(". <i>Choose a token that will return the time in 'Y-m-d H:i:s' format.</i>"),
'#default_value' => isset($settings['settings'][$field['name'] . '_date_token']) ? $settings['settings'][$field['name'] . '_date_token'] : NULL,
'#element_validate' => array(
'token_element_validate',
),
'#token_types' => array(
$entity_type,
),
'#states' => array(
'visible' => array(
':input[name="scheduling[' . $field['name'] . '_use_token]"]' => array(
'checked' => TRUE,
),
),
),
'#weight' => $base_weight,
);
$form[$field['set']][$field['name']]['#states'] = array(
'visible' => array(
':input[name="scheduling[' . $field['name'] . '_use_token]"]' => array(
'checked' => FALSE,
),
),
);
}
// Add the UI for browsing tokens.
$form['scheduling']['_tokens'] = array(
'#theme' => 'token_tree_link',
'#token_types' => array(
$entity_type,
),
'#global_types' => FALSE,
'#click_insert' => TRUE,
'#weight' => 3,
);
}
$form['reminder'] = array(
'#type' => 'fieldset',
'#title' => t('Reminder'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#tree' => TRUE,
);
$form['reminder']['send_reminder'] = array(
'#type' => 'checkbox',
'#title' => t('Send Reminder'),
'#description' => t('If checked, a reminder will be sent to registrants on the following date.'),
'#default_value' => isset($settings['send_reminder']) ? $settings['send_reminder'] : -1,
);
$form['reminder']['reminder_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Settings'),
'#collapsible' => FALSE,
'#states' => array(
'visible' => array(
':input[name="send_reminder"]' => array(
'checked' => TRUE,
),
),
),
);
$form['reminder']['reminder_settings']['reminder_date'] = array(
'#type' => 'textfield',
'#title' => t('Reminder Date'),
'#maxlength' => 25,
'#description' => t('When to send reminders. Format: %time. The date format is YYYY-MM-DD and %timezone is the time zone offset from UTC.', array(
'%time' => !empty($settings['open']) ? date_format(date_create($settings['reminder_date']), 'Y-m-d H:i:s O') : format_date(time(), 'custom', 'Y-m-d H:i:s O'),
'%timezone' => !empty($settings['open']) ? date_format(date_create($settings['reminder_date']), 'O') : format_date(time(), 'custom', 'O'),
)),
'#default_value' => !empty($settings['reminder_date']) ? $settings['reminder_date'] : '',
);
if ($date_popup_installed) {
$form['reminder']['reminder_settings']['reminder_date']['#type'] = 'date_popup';
$form['reminder']['reminder_settings']['reminder_date']['#date_format'] = 'Y-m-d H:i:s O';
$form['reminder']['reminder_settings']['reminder_date']['#description'] = t('When to send reminders. (This uses the !timezone.)', array(
'!timezone' => \Drupal::l(t('site default time zone'), \Drupal\Core\Url::fromRoute('system.regional_settings')),
));
unset($form['reminder']['reminder_settings']['reminder_date']['#maxlength']);
}
$form['reminder']['reminder_settings']['reminder_template'] = array(
'#type' => 'textarea',
'#title' => t('Template'),
'#default_value' => isset($settings['reminder_template']) ? $settings['reminder_template'] : '',
'#description' => t('The reminder message sent to registrants. Tokens are supported if the module is enabled, E.g., [node:title].'),
);
// Add token support:
if (\Drupal::moduleHandler()
->moduleExists('token')) {
$form['reminder']['reminder_settings']['token_tree'] = array(
'#theme' => 'token_tree',
'#token_types' => array(
$entity_type,
'registration',
),
'#global_types' => FALSE,
);
}
$form['settings'] = array(
'#type' => 'fieldset',
'#title' => t('Additional Settings'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#tree' => TRUE,
);
$form['settings']['upsert_registrants'] = array(
'#type' => 'checkbox',
'#title' => t('Automatically create and update registrant entities'),
'#description' => t('If selected, anonymous registrants will have a registrant entity automatically created and attached when the registration is saved. Additionally, if a module exposes registrant form fields on the registration form, those values will be set on the registrant entity.'),
'#default_value' => isset($settings['settings']['upsert_registrants']) ? $settings['settings']['upsert_registrants'] : NULL,
);
$form['settings']['multiple_registrations'] = array(
'#type' => 'checkbox',
'#title' => t('Allow multiple registrations'),
'#description' => t('If selected, each person can create multiple registrations for this event.'),
'#default_value' => isset($settings['settings']['multiple_registrations']) ? $settings['settings']['multiple_registrations'] : -1,
);
$form['settings']['maximum_spaces'] = array(
'#type' => 'textfield',
'#title' => t('Spaces allowed'),
'#size' => 5,
'#maxlength' => 10,
'#required' => TRUE,
'#description' => t('The maximum number of spaces allowed for each registrations. For no limit, use 0. (Default is 1)'),
'#default_value' => isset($settings['settings']['maximum_spaces']) ? $settings['settings']['maximum_spaces'] : 1,
);
// @FIXME
// // @FIXME
// // This looks like another module's variable. You'll need to rewrite this call
// // to ensure that it uses the correct configuration object.
// $form['settings']['from_address'] = array(
// '#type' => 'textfield',
// '#title' => t('From Address'),
// '#description' => t('From email address to use for confirmations, reminders, and broadcast emails.'),
// '#required' => TRUE,
// '#default_value' => isset($settings['settings']['from_address']) ? $settings['settings']['from_address'] : variable_get('site_mail', ini_get('sendmail_from')),
// );
$form['settings']['confirmation'] = array(
'#type' => 'textfield',
'#title' => t('Confirmation Message'),
'#description' => t('The message to display when someone registers. Leave blank for none.'),
'#size' => 60,
'#maxlength' => 120,
'#required' => FALSE,
'#default_value' => isset($settings['settings']['confirmation']) ? $settings['settings']['confirmation'] : 'Registration has been saved.',
);
$form['settings']['confirmation_redirect'] = array(
'#type' => 'textfield',
'#title' => t('Confirmation redirect path'),
'#description' => t('Optional path to redirect to when someone registers. Leave blank to redirect to the registration itself if the user has permission or the host entity if they do not.'),
'#size' => 60,
'#maxlength' => 120,
'#required' => FALSE,
'#default_value' => isset($settings['settings']['confirmation_redirect']) ? $settings['settings']['confirmation_redirect'] : '',
);
// Display the list of available placeholders if token module is installed.
if (\Drupal::moduleHandler()
->moduleExists('token')) {
$form['settings']['confirmation_redirect']['#description'] .= ' ' . t('Tokens may be used.');
$form['settings']['token_help'] = array(
'#type' => 'fieldset',
'#title' => t('Available Tokens'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#tree' => TRUE,
'token_help_details' => array(
'#theme' => 'token_tree',
'#token_types' => array(
$entity_type,
'registration',
),
),
);
}
// Allow other modules to add their own custom settings:
$form['settings'] += \Drupal::moduleHandler()
->invokeAll('registration_entity_settings', [
$settings,
]);
// Only show save if we're not on the field instance defaults:
if ($entity_id) {
$form['save'] = array(
'#type' => 'submit',
'#value' => t('Save Settings'),
);
}
return $form;
}