function theme_profile_admin_overview in Drupal 6
Same name and namespace in other branches
- 7 modules/profile/profile.admin.inc \theme_profile_admin_overview()
Theme the profile field overview into a drag and drop enabled table.
See also
Related topics
File
- modules/
profile/ profile.admin.inc, line 92 - Administrative page callbacks for the profile module.
Code
function theme_profile_admin_overview($form) {
drupal_add_css(drupal_get_path('module', 'profile') . '/profile.css');
// Add javascript if there's more than one field.
if (isset($form['submit'])) {
drupal_add_js(drupal_get_path('module', 'profile') . '/profile.js');
}
$rows = array();
$categories = array();
$category_number = 0;
foreach (element_children($form) as $key) {
// Don't take form control structures.
if (array_key_exists('category', $form[$key])) {
$field =& $form[$key];
$category = $field['category']['#default_value'];
if (!isset($categories[$category])) {
// Category classes are given numeric IDs because there's no guarantee
// class names won't contain invalid characters.
$categories[$category] = $category_number;
$category_field['#attributes']['class'] = 'profile-category profile-category-' . $category_number;
$rows[] = array(
array(
'data' => $category,
'colspan' => 7,
'class' => 'category',
),
);
$rows[] = array(
'data' => array(
array(
'data' => '<em>' . t('No fields in this category. If this category remains empty when saved, it will be removed.') . '</em>',
'colspan' => 7,
),
),
'class' => 'category-' . $category_number . '-message category-message category-populated',
);
// Make it dragable only if there is more than one field
if (isset($form['submit'])) {
drupal_add_tabledrag('profile-fields', 'order', 'sibling', 'profile-weight', 'profile-weight-' . $category_number);
drupal_add_tabledrag('profile-fields', 'match', 'sibling', 'profile-category', 'profile-category-' . $category_number);
}
$category_number++;
}
// Add special drag and drop classes that group fields together.
$field['weight']['#attributes']['class'] = 'profile-weight profile-weight-' . $categories[$category];
$field['category']['#attributes']['class'] = 'profile-category profile-category-' . $categories[$category];
// Add the row
$row = array();
$row[] = drupal_render($field['title']);
$row[] = drupal_render($field['name']);
$row[] = drupal_render($field['type']);
if (isset($form['submit'])) {
$row[] = drupal_render($field['category']);
$row[] = drupal_render($field['weight']);
}
$row[] = drupal_render($field['edit']);
$row[] = drupal_render($field['delete']);
$rows[] = array(
'data' => $row,
'class' => 'draggable',
);
}
}
if (empty($rows)) {
$rows[] = array(
array(
'data' => t('No fields available.'),
'colspan' => 7,
),
);
}
$header = array(
t('Title'),
t('Name'),
t('Type'),
);
if (isset($form['submit'])) {
$header[] = t('Category');
$header[] = t('Weight');
}
$header[] = array(
'data' => t('Operations'),
'colspan' => 2,
);
$output = theme('table', $header, $rows, array(
'id' => 'profile-fields',
));
$output .= drupal_render($form);
return $output;
}