function notifications_destination_address_subform in Notifications 6.4
Displays a destination field for each method
Parameters
$account: User account the destination is for
$destination: Destination object to populate one of the addresses
$send_methods: Array method => name to restrict the number of sending methods
$size: Address text field size
2 calls to notifications_destination_address_subform()
- notifications_destination_request_form in includes/
destination.inc - Form to request a message with a link to manage destination's subscriptions
- notifications_subscription_destination_subform in ./
notifications.module - Add destination subform
File
- includes/
destination.inc, line 95 - Destination management
Code
function notifications_destination_address_subform($account, $destination = NULL, $send_methods = NULL, $size = 40) {
$send_methods = isset($send_methods) ? $send_methods : notifications_send_methods($account);
if (!$send_methods) {
$form['warning']['#value'] = '<p>' . t('No sending methods available.') . '</p>';
return $form;
}
// Get address types for all these methods, without duplicates
$address_types = $address_method = array();
foreach ($send_methods as $method => $method_name) {
// We use method name if we don't have address name
$type = messaging_method_info($method, 'address_type');
$name = messaging_address_info($type, 'name');
$address_types[$type] = $name ? $name : $method_name;
$address_method[$method] = $type;
}
// This address type to method mapping will allow us to get a valid method from a destination
$form['destination_methods'] = array(
'#type' => 'value',
'#value' => $address_method,
);
$form['destination_account'] = array(
'#type' => 'value',
'#value' => $account,
);
$form['destination_address'] = array(
//'#type' => 'fieldset',
'#tree' => TRUE,
);
// Now depending on how many address types we adjust the title
if (count($address_types) > 1) {
$form['destination_address'] += array(
'#title' => t('Enter only a destination address.'),
'#type' => 'fieldset',
);
}
// We present a field for each address type
foreach ($address_types as $type => $name) {
$form['destination_address'][$type] = array(
'#title' => $name,
'#type' => 'textfield',
'#size' => $size,
'#default_value' => $destination && $type == $destination->type ? $destination->address : '',
);
}
return $form;
}