public function UcAddressesDefaultAddressFieldHandler::getFormField in Ubercart Addresses 7
Same name and namespace in other branches
- 6.2 handlers/uc_addresses.handlers.inc \UcAddressesDefaultAddressFieldHandler::getFormField()
Implements UcAddressesFieldHandler::getFormField().
Overrides UcAddressesFieldHandler::getFormField
File
- handlers/
uc_addresses.handlers.inc, line 148 - Field handlers for Ubercart Addresses address fields:
Class
- UcAddressesDefaultAddressFieldHandler
- Class for default address field.
Code
public function getFormField($form, $form_values) {
$fieldName = $this
->getFieldName();
$fieldValue = $this
->getAddress()
->getField($fieldName);
$default = isset($form_values[$fieldName]) ? $form_values[$fieldName] : $fieldValue;
$default_type = $this
->getProperty('default_type');
// Check if user already has a default address of type $type.
$default_address = $this
->getAddress()
->getAddressBook()
->getDefaultAddress($default_type);
if (!is_null($default_address)) {
return array(
$fieldName => array(
'#type' => 'checkbox',
'#title' => $this
->getFieldTitle(),
'#uc_addresses_default_address_suffix' => $this
->getProperty('suffix'),
'#default_value' => $default,
'#disabled' => $fieldValue,
'#required' => $this
->isFieldRequired(),
'#theme' => 'uc_addresses_default_address_checkbox',
),
);
}
else {
// No default address of type $type yet. Force default.
return array(
$fieldName => array(
'#type' => 'value',
'#value' => 1,
),
$fieldName . '_item' => array(
'#type' => 'checkbox',
'#title' => $this
->getFieldTitle(),
'#uc_addresses_default_address_suffix' => $this
->getProperty('suffix'),
'#default_value' => 1,
'#disabled' => TRUE,
'#required' => $this
->isFieldRequired(),
'#theme' => 'uc_addresses_default_address_checkbox',
),
);
}
}