/[drupal]/contributions/modules/profile_category_weight/profile_category_weight.module
ViewVC logotype

Contents of /contributions/modules/profile_category_weight/profile_category_weight.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Fri Sep 5 21:17:04 2008 UTC (14 months, 3 weeks ago) by hanoii
Branch: MAIN
CVS Tags: DRUPAL-5--1-0, HEAD
Branch point for: DRUPAL-5, DRUPAL-6--1
File MIME type: text/x-php
Initial commit. Configure weights for profile categories for the registration form.
1 <?php
2 // $Id$
3
4 function _profile_category_weight_form_id($category) {
5 $category = str_replace(' ', '_', $category);
6 return $category;
7 }
8
9 function _profile_category_weight_categories() {
10 $categories_weight = variable_get('profile_category_weight_categories', array());
11 $categories = array('account' => $categories_weight['account']);
12 $extra = _user_forms($null, NULL, NULL, 'register');
13 foreach ( $extra as $categ=>$categ_form){
14 $categories[$categ] = $categories_weight[$categ];
15 }
16
17 asort($categories);
18 return $categories;
19 }
20
21 function profile_category_weight_menu($may_cache) {
22 $items = array();
23
24 if ($may_cache) {
25 $items[]= array (
26 'path' => 'admin/settings/profile_category_weight',
27 'title' => t('Profile Category Weight'),
28 'callback' => 'drupal_get_form',
29 'callback arguments' => array('profile_category_weight_settings'),
30 'description' => t('Assign weight to profile categories.'),
31 );
32 } else {
33
34 }
35
36 return $items;
37 }
38
39 function profile_category_weight_settings_submit($form_id, $form_values) {
40 $op = isset($form_values['op']) ? $form_values['op'] : '';
41
42 if ($op == t('Reset to defaults')) {
43 variable_del('profile_category_weight_categories');
44 }
45 else {
46 $categories_values = array();
47 $categories = _profile_category_weight_categories();
48 foreach ( $categories as $category => $weight ) {
49 $category_form_id = _profile_category_weight_form_id($category);
50 $categories_values[$category] = $form_values[$category_form_id];
51 }
52 variable_set('profile_category_weight_categories', $categories_values);
53 }
54
55 if ($op == t('Reset to defaults')) {
56 drupal_set_message(t('The configuration options have been reset to their default values.'));
57 }
58 else {
59 drupal_set_message(t('The configuration options have been saved.'));
60 }
61
62 menu_rebuild();
63 }
64
65 function profile_category_weight_settings() {
66
67 $categories = _profile_category_weight_categories();
68 foreach ($categories as $category => $weight) {
69 $category_form_id = _profile_category_weight_form_id($category);
70 $form[$category_form_id] = array(
71 '#type' => 'weight',
72 '#title' => $category,
73 '#default_value' => $weight,
74 );
75 }
76
77 $form = system_settings_form($form);
78 $form['#base'] = 'profile_category_weight_settings';
79 return $form;
80 }
81
82 function profile_category_weight_form_alter($form_id, &$form) {
83 if ($form_id == 'user_register') {
84 $categories = _profile_category_weight_categories();
85 foreach ($categories as $category => $weight) {
86 if ( is_numeric($weight) ) {
87 $form[$category]['#weight'] = $weight;
88 }
89 }
90 }
91 }

  ViewVC Help
Powered by ViewVC 1.1.2