addressfield.api.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /**
  3. * @file
  4. * API documentation for Addressfield.
  5. */
  6. /**
  7. * Format generation callback.
  8. *
  9. * @param $format
  10. * The address format being generated.
  11. * @param $address
  12. * The address this format is generated for.
  13. * @param $context
  14. * An associative array of context information pertaining to how the address
  15. * format should be generated. If no mode is given, it will initialize to the
  16. * default value. The remaining context keys should only be present when the
  17. * address format is being generated for a field:
  18. * - mode: either 'form' or 'render'; defaults to 'render'.
  19. * - field: the field info array.
  20. * - instance: the field instance array.
  21. * - langcode: the langcode of the language the field is being rendered in.
  22. * - delta: the delta value of the given address.
  23. *
  24. * @ingroup addressfield_format
  25. */
  26. function CALLBACK_addressfield_format_callback(&$format, $address, $context = array()) {
  27. // No example.
  28. }
  29. /**
  30. * Allows modules to alter the default values for an address field.
  31. *
  32. * @param $default_values
  33. * The array of default values. The country is populated from the
  34. * 'default_country' widget setting.
  35. * @param $context
  36. * An array with the following keys:
  37. * - field: The field array.
  38. * - instance: The instance array.
  39. * - address: The current address values. Allows for per-country defaults.
  40. */
  41. function hook_addressfield_default_values_alter(&$default_values, $context) {
  42. // If no other default country was provided, set it to France.
  43. // Note: you might want to check $context['instance']['required'] and
  44. // skip setting the default country if the field is optional.
  45. if (empty($default_values['country'])) {
  46. $default_values['country'] = 'FR';
  47. }
  48. // Determine the country for which other defaults should be provided.
  49. $selected_country = $default_values['country'];
  50. if (isset($context['address']['country'])) {
  51. $selected_country = $context['address']['country'];
  52. }
  53. // Add defaults for the US.
  54. if ($selected_country == 'US') {
  55. $default_values['locality'] = 'New York';
  56. $default_values['administrative_area'] = 'NY';
  57. }
  58. }
  59. /**
  60. * Allows modules to alter the predefined address formats.
  61. *
  62. * @param $address_formats
  63. * The array of all predefined address formats.
  64. *
  65. * @see addressfield_get_address_format()
  66. */
  67. function hook_addressfield_address_formats_alter(&$address_formats) {
  68. // Remove the postal_code from the list of required fields for China.
  69. $address_formats['CN']['required_fields'] = array('locality', 'administrative_area');
  70. }
  71. /**
  72. * Allows modules to alter the predefined administrative areas.
  73. *
  74. * @param $administrative_areas
  75. * The array of all predefined administrative areas.
  76. *
  77. * @see addressfield_get_administrative_areas()
  78. */
  79. function hook_addressfield_administrative_areas_alter(&$administrative_areas) {
  80. // Alter the label of the Spanish administrative area with the iso code PM.
  81. $administrative_areas['ES']['PM'] = t('Balears / Baleares');
  82. // Add administrative areas for imaginary country XT, keyed by their
  83. // imaginary ISO codes.
  84. $administrative_areas['XT'] = array(
  85. 'A' => t('Aland'),
  86. 'B' => t('Bland'),
  87. );
  88. }
  89. /**
  90. * Allows modules to add arbitrary AJAX commands to the array returned from the
  91. * standard address field widget refresh.
  92. *
  93. * @param &$commands
  94. * The array of AJAX commands used to refresh the address field widget.
  95. * @param $form
  96. * The rebuilt form array.
  97. * @param $form_state
  98. * The form state array from the form.
  99. *
  100. * @see addressfield_standard_widget_refresh()
  101. */
  102. function hook_addressfield_standard_widget_refresh_alter(&$commands, $form, $form_state) {
  103. // Display an alert message.
  104. $commands[] = ajax_command_alert(t('The address field widget has been updated.'));
  105. }