Skip to content

Instantly share code, notes, and snippets.

@bleeDev
Last active December 30, 2015 04:29
Show Gist options
  • Save bleeDev/7775965 to your computer and use it in GitHub Desktop.
Save bleeDev/7775965 to your computer and use it in GitHub Desktop.
Change Address Field from Address 1/2 Text fields to Textarea
-- Thanks to David (@nadavoid) for working this out.
- [custom_module].module
<?php
/**
* Implements hook_ctools_plugin_directory().
*/
function [custom_module]_ctools_plugin_directory($module, $plugin) {
if ($module == 'addressfield') {
return 'plugins/addressfield/' . $plugin;
}
}
?>
- [custom_module]/plugins/addressfield/format/thoroughfare-textarea.inc
<?php
/**
* @file
* addressfield.inc
*
* Custom address formatters.
*/
/**
* Plugin definition for address field format.
*/
$plugin = array(
'title' => t('Thoroughfare as text area.'),
'format callback' => '[custom_module]_thoroughfare_textarea_generate',
'type' => 'address',
'weight' => -80,
);
/**
* Callback for plugin definition.
*/
function [custom_module]_thoroughfare_textarea_generate(&$format, $address, $context = array()) {
if (in_array($address['country'], array('US', 'CA'))) {
// Change Thoroughfare (Address 1) field to a textarea.
if ($context['mode'] == 'form') {
$format['street_block']['thoroughfare']['#widget_type'] = 'textarea';
$format['street_block']['thoroughfare']['#rows'] = '2';
$format['street_block']['thoroughfare']['#title'] = t('Address');
$format['street_block']['premise']['#access'] = FALSE;
}
// Convert newlines to breaks when displaying thoroughfare.
elseif ($context['mode'] == 'render') {
$format['street_block']['thoroughfare']['#render_type'] = 'markup';
$format['street_block']['thoroughfare']['#markup'] = nl2br($address['thoroughfare']);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment