function node_registration_form_node_type_form_alter in Node registration 7
Implements hook_form_FORM_ID_alter() for node_type_form().
Add registration options to node type form.
File
- ./
node_registration.module, line 750
Code
function node_registration_form_node_type_form_alter(&$form, &$form_state, $form_id = 'node_type_form') {
$type = $form['#node_type']->type;
if (!$type) {
return;
}
$form['#attached']['js'][] = drupal_get_path('module', 'node_registration') . '/node_registration.admin.js';
$form['#attributes']['class'][] = 'node-type-form';
$fields = db_query("SELECT c.field_name, ci.data FROM {field_config} c, {field_config_instance} ci WHERE ci.field_id = c.id AND c.type IN ('date', 'datetime', 'datestamp') AND ci.entity_type = ? AND bundle = ? AND c.deleted = 0 AND ci.deleted = 0", array(
'node',
$type,
));
$date_fields = array();
foreach ($fields as $field) {
// Add from field.
$data = unserialize($field->data);
$date_fields[$field->field_name] = $data['label'];
// Maybe there's a to field too.
$field_info = field_info_field($field->field_name);
$todate = !empty($field_info['settings']['todate']);
$value2 = isset($field_info['columns']['value2']);
if ($todate && $value2) {
$date_fields[$field->field_name . ':value2'] = $data['label'] . t(' (end date)');
}
}
$fields = db_query("SELECT c.field_name, ci.data FROM {field_config} c, {field_config_instance} ci WHERE ci.field_id = c.id AND c.type IN ('number_integer') AND ci.entity_type = ? AND bundle = ? AND c.deleted = 0 AND ci.deleted = 0", array(
'node',
$type,
));
$number_fields = array();
foreach ($fields as $field) {
$data = unserialize($field->data);
$number_fields[$field->field_name] = $data['label'];
}
$enabled = _node_registration_node_type_settings($type);
$form['registration'] = array(
'#type' => 'fieldset',
'#title' => t('Registration settings'),
'#group' => 'additional_settings',
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['registration']['registration_node_status'] = array(
'#type' => 'select',
'#title' => t('Enable registrations for this content type'),
'#options' => array(
'0' => t('Disabled'),
'1' => t('Enabled, on by default'),
'2' => t('Enabled, off by default'),
),
'#required' => TRUE,
'#default_value' => $enabled ? (int) $enabled->status : 0,
'#description' => t('If enabled, users will be allowed to register for this content type unless an administrator disables registrations on specific posts.'),
'#attributes' => array(
'class' => array(
'node-registration-status',
),
),
);
$form['registration']['registration_node_date_field'] = array(
'#type' => 'select',
'#title' => t('Field for event start date (and time)'),
'#options' => array(
'0' => '-- ' . t('None'),
) + $date_fields,
'#default_value' => $enabled ? $enabled->date_field : 0,
'#description' => t('Which field will be used to indicate start date (and time)? If empty, no automatic e-mails will be sent.'),
);
$form['registration']['registration_node_min_registration_date_field'] = array(
'#type' => 'select',
'#title' => t('Field for registration start date (and time)'),
'#options' => array(
'0' => '-- ' . t('None'),
) + $date_fields,
'#default_value' => $enabled ? $enabled->min_registration_date_field : 0,
'#description' => t('Which <strong>node field</strong> will be used as registration start date.'),
);
$form['registration']['registration_node_max_registration_date_field'] = array(
'#type' => 'select',
'#title' => t('Field for registration end date (and time)'),
'#options' => array(
'0' => '-- ' . t('None'),
) + $date_fields,
'#default_value' => $enabled ? $enabled->max_registration_date_field : 0,
'#description' => t('Which <strong>node field</strong> will be used as registration end date, instead of the variable .'),
);
$form['registration']['registration_node_capacity_field'] = array(
'#type' => 'select',
'#title' => t('Field for capacity'),
'#options' => array(
'0' => '-- ' . t('None'),
) + $number_fields,
'#default_value' => $enabled ? $enabled->capacity_field : 0,
'#description' => t('Which node field will be used as Capacity source, <strong>instead of the node settings field Capacity</strong>.'),
);
array_unshift($form['#submit'], 'node_registration_node_type_form_submit');
}