/[drupal]/contributions/modules/addresses/addresses.settings.inc
ViewVC logotype

Diff of /contributions/modules/addresses/addresses.settings.inc

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

revision 1.22, Thu Jan 8 08:52:45 2009 UTC revision 1.23, Tue Jan 20 20:31:42 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: addresses.settings.inc,v 1.21 2008/11/17 16:01:56 alexiswilke Exp $  // $Id: addresses.settings.inc,v 1.22 2009/01/08 08:52:45 brmassa Exp $
3  /**  /**
4   * @author Bruno Massa   * @author Bruno Massa
5   * @file   * @file
# Line 13  Line 13 
13   * @ingroup form   * @ingroup form
14   */   */
15  function _addresses_addressesfieldapi_form($fields = array(), $values = array()) {  function _addresses_addressesfieldapi_form($fields = array(), $values = array()) {
16      $field_weights = variable_get('addresses_field_weight', array());
17    
18    // Let users select if the address is the primary    // Let users select if the address is the primary
19    if (!empty($fields['is_primary'])) {    if (!empty($fields['is_primary'])) {
20      $form['is_primary'] = array(      $form['is_primary'] = array(
21        '#type'           => 'checkbox',        '#type'           => 'checkbox',
22        '#title'          => t('Default address'),        '#title'          => t('Default address'),
23        '#default_value'  => isset($values['is_primary']) ? $values['is_primary'] : ''        '#default_value'  => isset($values['is_primary']) ? $values['is_primary'] : '',
24          '#weight'         => empty($field_weights['is_primary']['weight']) ? 0 :
25            $field_weights['is_primary']['weight'],
26      );      );
27    }    }
28    
# Line 32  function _addresses_addressesfieldapi_fo Line 36  function _addresses_addressesfieldapi_fo
36        '#maxlength'      => 75,        '#maxlength'      => 75,
37        '#description'    => t('e.g. a place of business, venue, meeting point'),        '#description'    => t('e.g. a place of business, venue, meeting point'),
38        '#attributes'     => NULL,        '#attributes'     => NULL,
39        '#required'       => ($fields['aname'] == ADDRESSES_FIELD_REQUIRED)        '#required'       => ($fields['aname'] == ADDRESSES_FIELD_REQUIRED),
40          '#weight'         => empty($field_weights['aname']['weight']) ? 0 :
41            $field_weights['aname']['weight'],
42      );      );
43    }    }
44    
# Line 50  function _addresses_addressesfieldapi_fo Line 56  function _addresses_addressesfieldapi_fo
56        '#description'    => NULL,        '#description'    => NULL,
57        '#extra'          => 0,        '#extra'          => 0,
58        '#multiple'       => FALSE,        '#multiple'       => FALSE,
59        '#required'       => ($fields['country'] == ADDRESSES_FIELD_REQUIRED)        '#required'       => ($fields['country'] == ADDRESSES_FIELD_REQUIRED),
60          '#weight'         => empty($field_weights['country']['weight']) ? 0 :
61            $field_weights['country']['weight'],
62      );      );
63    }    }
64    
# Line 63  function _addresses_addressesfieldapi_fo Line 71  function _addresses_addressesfieldapi_fo
71        '#size'           => 16,        '#size'           => 16,
72        '#title'          => t('State / Province'),        '#title'          => t('State / Province'),
73        '#type'           => 'textfield',        '#type'           => 'textfield',
74          '#weight'         => empty($field_weights['province']['weight']) ? 0 :
75            $field_weights['province']['weight'],
76      );      );
77      $form['#element_validate'][] = '_addresses_province_validate';      $form['#element_validate'][] = '_addresses_province_validate';
78    }    }
# Line 75  function _addresses_addressesfieldapi_fo Line 85  function _addresses_addressesfieldapi_fo
85        '#default_value'  => isset($values['city']) ? $values['city'] : '',        '#default_value'  => isset($values['city']) ? $values['city'] : '',
86        '#size'           => 50,        '#size'           => 50,
87        '#maxlength'      => 255,        '#maxlength'      => 255,
88        '#required'       => ($fields['city'] == ADDRESSES_FIELD_REQUIRED)        '#required'       => ($fields['city'] == ADDRESSES_FIELD_REQUIRED),
89          '#weight'         => empty($field_weights['city']['weight']) ? 0 :
90            $field_weights['city']['weight'],
91      );      );
92    }    }
93    
# Line 87  function _addresses_addressesfieldapi_fo Line 99  function _addresses_addressesfieldapi_fo
99        '#default_value'  => isset($values['street']) ? $values['street'] : '',        '#default_value'  => isset($values['street']) ? $values['street'] : '',
100        '#size'           => 50,        '#size'           => 50,
101        '#maxlength'      => 255,        '#maxlength'      => 255,
102        '#required'       => ($fields['street'] == ADDRESSES_FIELD_REQUIRED)        '#required'       => ($fields['street'] == ADDRESSES_FIELD_REQUIRED),
103          '#weight'         => empty($field_weights['street']['weight']) ? 0 :
104            $field_weights['street']['weight'],
105      );      );
106      if (!empty($fields['additional'])) {      if (!empty($fields['additional'])) {
107        $form['additional'] = array(        $form['additional'] = array(
# Line 95  function _addresses_addressesfieldapi_fo Line 109  function _addresses_addressesfieldapi_fo
109          '#title'          => t('Additional'),          '#title'          => t('Additional'),
110          '#default_value'  => isset($values['additional']) ? $values['additional'] : '',          '#default_value'  => isset($values['additional']) ? $values['additional'] : '',
111          '#size'           => 50,          '#size'           => 50,
112          '#maxlength'      => 255          '#maxlength'      => 255,
113            '#weight'         => empty($field_weights['additional']['weight']) ? 0 :
114              $field_weights['additional']['weight'],
115        );        );
116      }      }
117    }    }
# Line 108  function _addresses_addressesfieldapi_fo Line 124  function _addresses_addressesfieldapi_fo
124        '#default_value'  => isset($values['postal_code']) ? $values['postal_code'] : '',        '#default_value'  => isset($values['postal_code']) ? $values['postal_code'] : '',
125        '#size'           => 16,        '#size'           => 16,
126        '#maxlength'      => 16,        '#maxlength'      => 16,
127        '#required'       => ($fields['postal_code'] == ADDRESSES_FIELD_REQUIRED)        '#required'       => ($fields['postal_code'] == ADDRESSES_FIELD_REQUIRED),
128          '#weight'         => empty($field_weights['postal_code']['weight']) ? 0 :
129            $field_weights['postal_code']['weight'],
130      );      );
131    }    }
132    
# Line 223  function _addresses_settings(&$form_stat Line 241  function _addresses_settings(&$form_stat
241      $rows[] = array($columns[0][$row], $columns[1][$row], $columns[2][$row], $columns[3][$row]);      $rows[] = array($columns[0][$row], $columns[1][$row], $columns[2][$row], $columns[3][$row]);
242    }    }
243    $form['addresses_format'] = array(    $form['addresses_format'] = array(
     '#children'       => theme('table', array(), $rows),  
244      '#collapsed'      => TRUE,      '#collapsed'      => TRUE,
245      '#collapsible'    => TRUE,      '#collapsible'    => TRUE,
246      '#description'    => t('Change how the addresses are displayed, for each country. The Default is used if the country doesnt have a preset address format.'),      '#description'    => t('Change how the addresses are displayed, for each country. The Default is used if the country doesnt have a preset address format.'),
# Line 231  function _addresses_settings(&$form_stat Line 248  function _addresses_settings(&$form_stat
248      '#title'          => t('Address formats'),      '#title'          => t('Address formats'),
249    );    );
250    
251      // Field weight
252      $fields        = module_invoke_all('addressesfieldapi', 'fields');
253      $field_weights = variable_get('addresses_field_weight', array());
254      $form['addresses_field_weight'] = array(
255        '#collapsed'      => $field_weights,
256        '#collapsible'    => TRUE,
257        '#description'    => t('Choose what fields should appear first.'),
258        '#theme'          => 'addresses_field_weight',
259        '#title'          => t('Field Order'),
260        '#type'           => 'fieldset',
261        '#tree'           => TRUE,
262      );
263      foreach ($fields as $field_code => $field) {
264        $form['addresses_field_weight'][$field_code] = array(
265          '#tree'           => TRUE,
266        );
267        $form['addresses_field_weight'][$field_code]['field'] = array(
268          '#attributes'     => array('class' => 'field'),
269          '#type'           => 'markup',
270          '#value'          => $field['title'],
271        );
272        $form['addresses_field_weight'][$field_code]['weight'] = array(
273          '#attributes'     => array('class' => 'field'),
274          '#default_value'  => $field_weights[$field_code]['weight'],
275          '#type'           => 'weight',
276        );
277      }
278    
279    // We will use the this function that automatically    // We will use the this function that automatically
280    // save all form fields into global variables    // save all form fields into global variables
281    $form = system_settings_form($form);    $form = system_settings_form($form);
# Line 333  function _addresses_settings_format(&$fo Line 378  function _addresses_settings_format(&$fo
378   *   *
379   * @ingroup themeable   * @ingroup themeable
380   */   */
381  function theme_addresses_elements($element) {  function theme_addresses_elements(&$element) {
382    return theme('form_element', $element, '<div class="addresses-form">'. $element['#children'] .'</div>');    return theme('form_element', $element, '<div class="addresses-form">'. $element['#children'] .'</div>');
383  }  }
384    
# Line 347  function theme_addresses_elements($eleme Line 392  function theme_addresses_elements($eleme
392   *   String. The single line address   *   String. The single line address
393   * @ingroup themeable   * @ingroup themeable
394   */   */
395  function theme_addresses_settings_fields($form) {  function theme_addresses_settings_fields(&$form) {
396    foreach (element_children($form) as $ftype) {    foreach (element_children($form) as $ftype) {
397      $field = &$form[$ftype];      $field = &$form[$ftype];
398      $rows[] = array(      $rows[] = array(
# Line 366  function theme_addresses_settings_fields Line 411  function theme_addresses_settings_fields
411    $output .= drupal_render($form);    $output .= drupal_render($form);
412    
413    return $output;    return $output;
414    }
415    
416    /**
417     * Add a draggable item effect on fields.
418     *
419     * @param $form
420     *   Array. The address field weight values.
421     * @return
422     *   String. The table with draggable items
423     * @ingroup themeable
424     */
425    function theme_addresses_field_weight(&$form) {
426      drupal_add_tabledrag('addresses-field-weight', 'order', 'sibling', 'field');
427      foreach (element_children($form) as $field) {
428        $rows[] = array(
429          'class' => 'draggable',
430          'data'  => array(
431            drupal_render($form[$field]['field']),
432            drupal_render($form[$field]['weight'])
433          ),
434        );
435      }
436      return theme('table', array(), $rows, array('id' => 'addresses-field-weight')) . drupal_render($form);
437  }  }

Legend:
Removed from v.1.22  
changed lines
  Added in v.1.23

  ViewVC Help
Powered by ViewVC 1.1.2