function notifications_custom_fields_form in Notifications 6.4
Same name and namespace in other branches
- 6 notifications_custom/notifications_custom.admin.inc \notifications_custom_fields_form()
Fields form: edit /add fields to custom subscription type
1 string reference to 'notifications_custom_fields_form'
- notifications_custom_menu in notifications_custom/
notifications_custom.module - Implementation of hook_menu().
File
- notifications_custom/
notifications_custom.admin.inc, line 171 - Custom notifications module (admin features)
Code
function notifications_custom_fields_form($form_state, $custom_type) {
notifications_include('object.inc');
$subscription = notifications_build_subscription($custom_type);
$form['subscription'] = array(
'#type' => 'value',
'#value' => $subscription,
);
// Now the hard part, which are the fields. Only when subscriptions is created.
$form['fields'] = array(
'#title' => t('Fields'),
'#type' => 'fieldset',
'#tree' => 'true',
'#theme' => 'notifications_custom_fields',
);
// Take the values from form state (if submitted) or from the subscription itself
$fields = array();
if (!empty($form_state['submitted'])) {
$fields = notifications_field_parse_submitted($form_state, 'fields');
}
else {
$fields = $subscription
->get_fields_array();
}
// Build the form with current fields
if ($fields) {
foreach ($fields as $fid => $data) {
$form['fields']['type'][$fid] = array(
'#type' => 'hidden',
'#value' => $data['type'],
);
$form['fields']['name'][$fid] = array(
'#value' => notifications_subscription_fields($data['type'], 'name'),
);
$form['fields']['delete'][$fid] = array(
'#type' => 'checkbox',
'#default_value' => 0,
);
$form['fields']['value'][$fid] = array(
'#type' => 'value',
'#value' => $data['value'],
);
// Generate the editable field value and pass the value only if it doesn't come from a previous submission
if (empty($data['edit'])) {
$form['fields']['edit'][$fid] = $subscription
->field_element($data['type'], $data['value']);
}
else {
$form['fields']['edit'][$fid] = $subscription
->field_element($data['type']);
$form['fields']['edit'][$fid]['#default_value'] = $data['edit'];
}
}
}
else {
$form['fields']['#description'] = t('You have to define at least one field for this subscription.');
}
$form['fields']['name']['new'] = array(
'#type' => 'select',
'#options' => notifications_subscription_fields(NULL, 'name'),
);
$form['fields']['delete']['new'] = array(
'#value' => t('new'),
);
$form['fields']['edit']['new'] = array(
'#type' => 'submit',
'#value' => t('Add new field'),
'#submit' => array(
'notifications_custom_fields_form_add_field',
),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save fields'),
);
return $form;
}