Projet

Général

Profil

Paste
Télécharger (1,4 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / addressfield / plugins / format / name-full.inc @ fbb05e21

1
<?php
2

    
3
/**
4
 * @file
5
 * Generates a first name + last name format.
6
 */
7

    
8
$plugin = array(
9
  'title' => t('Name (First name, Last name)'),
10
  'format callback' => 'addressfield_format_name_full_generate',
11
  'type' => 'name',
12
  'weight' => 0,
13
);
14

    
15
/**
16
 * Format callback.
17
 *
18
 * @see CALLBACK_addressfield_format_callback()
19
 */
20
function addressfield_format_name_full_generate(&$format, $address) {
21
  $format['name_block'] = array(
22
    '#type' => 'addressfield_container',
23
    '#attributes' => array(
24
      'class' => array('addressfield-container-inline', 'name-block'),
25
    ),
26
    '#weight' => -100,
27
    // The addressfield is considered empty without a country, hide all fields
28
    // until one is selected.
29
    '#access' => !empty($address['country']),
30
  );
31
  // Maxlength is set to 127 so that the name_line still can be created without
32
  // exceeding the char limit from the database.
33
  $format['name_block']['first_name'] = array(
34
    '#title' => t('First name'),
35
    '#size' => 30,
36
    '#maxlength' => 127,
37
    '#required' => TRUE,
38
    '#attributes' => array(
39
      'class' => array('first-name'),
40
      'autocomplete' => 'given-name',
41
    ),
42
  );
43
  $format['name_block']['last_name'] = array(
44
    '#title' => t('Last name'),
45
    '#size' => 30,
46
    '#maxlength' => 127,
47
    '#required' => TRUE,
48
    '#prefix' => ' ',
49
    '#attributes' => array(
50
      'class' => array('last-name'),
51
      'autocomplete' => 'family-name',
52
    ),
53
  );
54
}