function addressfield_generate in Address Field 7
Generate a format for a given address.
Parameters
$address: The address format being generated.
$handlers: The format handlers to use to generate the format.
$context: An associative array of context information pertaining to how the address format should be generated. If no mode is given, it will initialize to the default value. The remaining context keys should only be present when the address format is being generated for a field:
- mode: either 'form' or 'render'; defaults to 'render'.
- field: the field info array.
- instance: the field instance array.
- langcode: the langcode of the language the field is being rendered in.
- delta: the delta value of the given address.
Return value
A renderable array suitable for use as part of a form (if 'mode' is 'form') or for formatted address output when passed to drupal_render().
Related topics
3 calls to addressfield_generate()
- addressfield_field_formatter_view in ./
addressfield.module - Implements hook_field_formatter_view().
- addressfield_field_widget_form in ./
addressfield.module - Implements hook_field_widget_form()
- addressfield_tokens in ./
addressfield.tokens.inc - Implements hook_tokens().
File
- ./
addressfield.module, line 172 - Defines a field for attaching country-specific addresses to entities.
Code
function addressfield_generate($address, array $handlers, array $context = array()) {
// If no mode is given in the context array, default it to 'render'.
if (empty($context['mode'])) {
$context['mode'] = 'render';
}
ctools_include('plugins');
$format = array();
// Add the handlers, ordered by weight.
$plugins = addressfield_format_plugins();
$format['#handlers'] = array_intersect(array_keys($plugins), $handlers);
foreach ($format['#handlers'] as $handler) {
if ($callback = ctools_plugin_load_function('addressfield', 'format', $handler, 'format callback')) {
$callback($format, $address, $context);
}
}
// Store the address in the format, for processing.
$format['#address'] = $address;
// Post-process the format stub, depending on the rendering mode.
if ($context['mode'] == 'form') {
$format['#addressfield'] = TRUE;
$format['#process'][] = 'addressfield_process_format_form';
}
elseif ($context['mode'] == 'render') {
$format['#pre_render'][] = 'addressfield_render_address';
}
return $format;
}