name-full.inc 1.4 KB

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