summaryrefslogtreecommitdiff
path: root/modules/profile
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2005-10-07 06:11:12 +0000
committerDries Buytaert <dries@buytaert.net>2005-10-07 06:11:12 +0000
commit7e1527ee61bc10b3765b95b9af8faaa2254da5a8 (patch)
tree2225c7f571b4a3f635564f8281406a12b2a271a7 /modules/profile
parent7b5b460534e5c54b07d28467c2aa2fc670c714e4 (diff)
downloadbrdo-7e1527ee61bc10b3765b95b9af8faaa2254da5a8.tar.gz
brdo-7e1527ee61bc10b3765b95b9af8faaa2254da5a8.tar.bz2
- Patch #29465: new form API by Adrian et al.
TODO: + The contact.module was broken; a new patch for contact.module is needed. + Documentation is needed. + The most important modules need to be updated ASAP.
Diffstat (limited to 'modules/profile')
-rw-r--r--modules/profile/profile.module117
1 files changed, 35 insertions, 82 deletions
diff --git a/modules/profile/profile.module b/modules/profile/profile.module
index 07e7b01cf..b329cc892 100644
--- a/modules/profile/profile.module
+++ b/modules/profile/profile.module
@@ -44,8 +44,8 @@ function profile_block($op = 'list', $delta = 0, $edit = array()) {
$fields[$record->name] = $record->title;
}
$fields['user_profile'] = t('Link to full user profile');
- $output .= form_checkboxes(t('Profile fields to display'), 'profile_block_author_fields', variable_get('profile_block_author_fields', NULL), $fields, t('Select which profile fields you wish to display in the block. Only fields designated as public in the <a href="%profile-admin">profile field configuration</a> are available.', array('%profile-admin' => url('admin/settings/profile'))));
- return $output;
+ $form['profile_block_author_fields'] = array(type => 'checkboxes', title => t('Profile fields to display'), default_value => variable_get('profile_block_author_fields', NULL), options => $fields, description => t('Select which profile fields you wish to display in the block. Only fields designated as public in the <a href="%profile-admin">profile field configuration</a> are available.', array('%profile-admin' => url('admin/settings/profile'))));
+ return $form;
}
else if ($op == 'save' && $delta == 0) {
variable_set('profile_block_author_fields', $edit['profile_block_author_fields']);
@@ -297,7 +297,8 @@ function profile_view_profile($user) {
if ($value = profile_view_field($user, $field)) {
$description = ($field->visibility == PROFILE_PRIVATE) ? t('The content of this field is private and only visible to yourself.') : '';
$title = ($field->type != 'checkbox') ? check_plain($field->title) : '';
- $fields[$field->category][$field->name] = form_item($title, $value, $description);
+ $form = array(type => 'item', title => $title, value => $value, description => $description);
+ $fields[$field->category][$field->name] = form_render(_form_builder($form));
}
}
@@ -327,23 +328,25 @@ function profile_form_profile($edit, $user, $category) {
$result = db_query("SELECT * FROM {profile_fields} WHERE LOWER(category) = LOWER('%s') ORDER BY weight", $category);
// We use LOWER('%s') instead of PHP's strtolower() to avoid UTF-8 conversion issues.
}
-
- $fields = array();
+ // Only add form group if items exist
+ if (db_num_rows($result)) {
+ $fields[$category] = array(type => 'fieldset', title => $category);
+ }
while ($field = db_fetch_object($result)) {
$category = $field->category;
switch ($field->type) {
case 'textfield':
- case 'url':
- $fields[$category] .= form_textfield(check_plain($field->title), $field->name, $edit[$field->name], 60, 255, _profile_form_explanation($field), NULL, $field->required);
+ case 'url':
+ $fields[$category][$field->name] = array(type => 'textfield', title => check_plain($field->title), default_value => $edit[$field->name], size => 60, maxlength => 255, description => _profile_form_explanation($field), required => $field->required);
break;
- case 'textarea':
- $fields[$category] .= form_textarea(check_plain($field->title), $field->name, $edit[$field->name], 60, 5, _profile_form_explanation($field), NULL, $field->required);
+ case 'textarea':
+ $fields[$category][$field->name] = array(type => 'textarea', title => check_plain($field->title), default_value => $edit[$field->name], cols => 60, rows => 5, description => _profile_form_explanation($field), required => $field->required);
break;
case 'list':
- $fields[$category] .= form_textarea(check_plain($field->title), $field->name, $edit[$field->name], 60, 5, _profile_form_explanation($field), NULL, $field->required);
+ $fields[$category][$field->name] = array(type => 'textarea', title => check_plain($field->title), default_value => $edit[$field->name], cols => 60, rows => 5, description => _profile_form_explanation($field), required => $field->required);
break;
- case 'checkbox':
- $fields[$category] .= form_checkbox(check_plain($field->title), $field->name, 1, $edit[$field->name], _profile_form_explanation($field), NULL, $field->required);
+ case 'checkbox':
+ $fields[$category][$field->name] = array(type => 'checkbox', title => check_plain($field->title), return_value => 1, default_value => $edit[$field->name], description => _profile_form_explanation($field), required => $field->required);
break;
case 'selection':
$options = array('--');
@@ -353,21 +356,14 @@ function profile_form_profile($edit, $user, $category) {
$options[$line] = $line;
}
}
-
- $fields[$category] .= form_select(check_plain($field->title), $field->name, $edit[$field->name], $options, _profile_form_explanation($field), 0, 0, $field->required);
+ $fields[$category][$field->name] = array(type => 'select', title => check_plain($field->title), default_value => $edit[$field->name], options => $options, description => _profile_form_explanation($field), required => $field->required);
break;
case 'date':
- $fields[$category] .= _profile_date_field($field, $edit);
+ $fields[$category][$field->name] = array(type => 'date', title => check_plain($field->title), default_value => $edit[$field->name], description, description => _profile_form_explanation($field), required => $field->required);
break;
}
}
-
- if ($fields) {
- foreach ($fields as $category => $data) {
- $output[] = array('title' => $category, 'data' => $data);
- }
- return $output;
- }
+ return $fields;
}
/**
@@ -381,46 +377,6 @@ function _profile_update_user_fields(&$fields, $account) {
}
}
-/**
- * Helper function: output a date selector
- */
-function _profile_date_field($field, $edit) {
- // Default to current date
- if (!isset($edit[$field->name])) {
- $edit[$field->name] = array('day' => format_date(time(), 'custom', 'j'),
- 'month' => format_date(time(), 'custom', 'n'),
- 'year' => format_date(time(), 'custom', 'Y'));
- }
-
- // Determine the order of day, month, year in the site's chosen date format.
- $format = variable_get('date_format_short', 'm/d/Y');
- $sort = array();
- $sort['day'] = max(strpos($format, 'd'), strpos($format, 'j'));
- $sort['month'] = max(strpos($format, 'm'), strpos($format, 'M'));
- $sort['year'] = strpos($format, 'Y');
- asort($sort);
- $order = array_keys($sort);
-
- // Output multi-selector for date
- $output = '<div class="container-inline">';
- foreach ($order as $type) {
- switch ($type) {
- case 'day':
- $options = drupal_map_assoc(range(1, 31));
- break;
- case 'month':
- $options = drupal_map_assoc(range(1, 12), '_profile_map_month');
- break;
- case 'year':
- $options = drupal_map_assoc(range(1900, 2050));
- break;
- }
- $output .= form_select('', $field->name .']['. $type, $edit[$field->name][$type], $options, '', 0, 0);
- }
- $output .= '</div>';
-
- return form_item(check_plain($field->title), $output, _profile_form_explanation($field), NULL, $field->required);
-}
/**
* Helper function for usage with drupal_map_assoc
@@ -585,39 +541,36 @@ function profile_admin_delete($fid) {
drupal_goto('admin/settings/profile');
}
else {
- $output = theme('confirm',
- t('Do you want to remove the field %field?',
+ return confirm_form('profile_confirm_delete', $form, t('Do you want to remove the field %field?',
array('%field' => $field->title)),
- 'admin/settings/profile');
- return $output;
+ 'admin/settings/profile', '', t('Delete'), t('Cancel'));
}
}
function _profile_field_form($type, $edit = array()) {
-
- $group = form_textfield(t('Category'), 'category', $edit['category'], 60, 128, t('The category the new field should be part of. Categories are used to group fields logically. An example category is "Personal information".'));
- $group .= form_textfield(t('Title'), 'title', $edit['title'], 60, 128, t('The title of the new field. The title will be shown to the user. An example title is "Favorite color".'));
- $group .= form_textfield(t('Form name'), 'name', $edit['name'], 60, 128, t('The name of the field. The form name is not shown to the user but used internally in the HTML code and URLs.
+
+ $form['fields'] = array(type => 'fieldset', title => t('Field settings'));
+ $form['fields']['category'] = array(type => 'textfield', title => t('Category'), default_value => $edit['category'], size => 60, maxlength => 128, description => t('The category the new field should be part of. Categories are used to group fields logically. An example category is "Personal information".'));
+ $form['fields']['title'] = array(type => 'textfield', title => t('Title'), default_value => $edit['title'], size => 60, maxlength => 128, description => t('The title of the new field. The title will be shown to the user. An example title is "Favorite color".'));
+ $form['fields']['name'] = array(type => 'textfield', title => t('Form name'), default_value => $edit['name'], size => 60, maxlength => 128, description => t('The name of the field. The form name is not shown to the user but used internally in the HTML code and URLs.
Unless you know what you are doing, it is highly recommended that you prefix the form name with <code>profile_</code> to avoid name clashes with other fields. Spaces or any other special characters except dash (-) and underscore (_) are not allowed. An example name is "profile_favorite_color" or perhaps just "profile_color".'));
- $group .= form_textarea(t('Explanation'), 'explanation', $edit['explanation'], 60, 5, t('An optional explanation to go with the new field. The explanation will be shown to the user.'));
+ $form['fields']['explanation'] = array(type => 'textarea', title => t('Explanation'), default_value => $edit['explanation'], cols => 60, rows => 5, description => t('An optional explanation to go with the new field. The explanation will be shown to the user.'));
if ($type == 'selection') {
- $group .= form_textarea(t('Selection options'), 'options', $edit['options'], 60, 5, t('A list of all options. Put each option on a separate line. Example options are "red", "blue", "green", etc.'));
+ $form['fields']['options'] = array(type => 'textarea', title => t('Selection options'), default_value => $edit['options'], cols => 60, rows => 5, description => t('A list of all options. Put each option on a separate line. Example options are "red", "blue", "green", etc.'));
}
- $group .= form_weight(t('Weight'), 'weight', $edit['weight'], 5, t('The weights define the order in which the form fields are shown. Lighter fields "float up" towards the top of the category.'));
- $group .= form_radios(t('Visibility'), 'visibility', $edit['visibility'], array(PROFILE_HIDDEN => t('Hidden profile field, only accessible by administrators, modules and themes.'), PROFILE_PRIVATE => t('Private field, content only available to privileged users.'), PROFILE_PUBLIC => t('Public field, content shown on profile page but not used on member list pages.'), PROFILE_PUBLIC_LISTINGS => t('Public field, content shown on profile page and on member list pages.')));
+ $form['fields']['weight'] = array(type => 'weight', title => t('Weight'), default_value => $edit['weight'], delta => 5, description => t('The weights define the order in which the form fields are shown. Lighter fields "float up" towards the top of the category.'));
+ $form['fields']['visibility'] = array(type => 'radios', title => t('Visibility'), default_value => $edit['visibility'], options => array(PROFILE_HIDDEN => t('Hidden profile field, only accessible by administrators, modules and themes.'), PROFILE_PRIVATE => t('Private field, content only available to privileged users.'), PROFILE_PUBLIC => t('Public field, content shown on profile page but not used on member list pages.'), PROFILE_PUBLIC_LISTINGS => t('Public field, content shown on profile page and on member list pages.')));
if ($type == 'selection' || $type == 'list') {
- $group .= form_textfield(t('Page title'), 'page', $edit['page'], 60, 128, t('The title of the page showing all users with the specified field. The word <code>%value</code> will be substituted with the corresponding value. An example page title is "People whose favorite color is %value". Only applicable if the field is configured to be shown on member list pages.'));
+ $form['fields']['page'] = array(type => 'textfield', title => t('Page title'), default_value => $edit['page'], size => 60, maxlength => 128, description => t('The title of the page showing all users with the specified field. The word <code>%value</code> will be substituted with the corresponding value. An example page title is "People whose favorite color is %value". Only applicable if the field is configured to be shown on member list pages.'));
}
else {
- $group .= form_textfield(t('Page title'), 'page', $edit['page'], 60, 128, t('The title of the page showing all users with the specified field. Only applicable if the field is configured to be shown on member listings.'));
+ $form['fields']['page'] = array(type => 'textfield', title => t('Page title'), default_value => $edit['page'], size => 60, maxlength => 128, description => t('The title of the page showing all users with the specified field. Only applicable if the field is configured to be shown on member listings.'));
}
- $group .= form_checkbox(t('The user must enter a value.'), 'required', 1, $edit['required']);
- $group .= form_checkbox(t('Visible in user registration form.'), 'register', 1, $edit['register']);
-
- $output = form_group(t('Field settings'), $group);
- $output .= form_submit(t('Save field'));
+ $form['fields']['required'] = array(type => 'checkbox', title => t('The user must enter a value.'), return_value => 1, default_value => $edit['required']);
+ $form['fields']['register'] = array(type => 'checkbox', title => t('Visible in user registration form.'), return_value => 1, default_value => $edit['register']);
+ $form['submit'] = array(type => 'submit', value => t('Save field'));
- return form($output);
+ return drupal_get_form('_profile_field_form', $form);
}
/**