public static function UcAddressesTestCase::getEditAddressValues in Ubercart Addresses 7
Same name and namespace in other branches
- 6.2 tests/UcAddressesTestCase.test \UcAddressesTestCase::getEditAddressValues()
Generates an array of values to post into an address form
@todo Think of which values go in the values array.
Parameters
array $parents: The parent form elements.
array $values: (Some of) the values to use in the address form.
string $context: The context of the address form. This is to determine which address fields should be available.
string $prefix: Optionally prefixes every field name
Return value
array An array with for each field a value.
17 calls to UcAddressesTestCase::getEditAddressValues()
- UcAddressesAddressBookAdminAllTestCase::testDoubleAddresses in tests/
uc_addresses.addressbook.test - Test if double addresses are not saved.
- UcAddressesApiTestCase::testAddressBookCrud in tests/
uc_addresses.api.test - Tests if addresses can be added, saved and deleted.
- UcAddressesApiTestCase::testAddressOutput in tests/
uc_addresses.api.test - Tests if address objects can be converted to a string.
- UcAddressesApiTestCase::testFieldHandlerApi in tests/
uc_addresses.api.test - Tests field handler with an UcAddressesSchemaAddress.
- UcAddressesApiTestCase::testMultipleAddressBooks in tests/
uc_addresses.api.test - Tests if address loading works as expected across multiple address books.
File
- tests/
UcAddressesTestCase.test, line 348 - Contains base class for Ubercart Addresses tests.
Class
- UcAddressesTestCase
- Base class for Ubercart Addresses tests.
Code
public static function getEditAddressValues($parents = array(), $values = array(), $context = 'default', $prefix = '') {
// Initialize values array.
$form_values = array();
// Calculate parent string if needed.
$parent_string = '';
if (count($parents) > 0) {
foreach ($parents as $parent) {
if ($parent_string) {
$parent_string = $parent_string . '[' . $parent . ']';
}
else {
$parent_string = $parent;
}
}
}
$address = UcAddressesAddressBook::newAddress();
$handlers = uc_addresses_get_address_field_handler_instances($address, $context);
foreach ($handlers as $fieldname => $handler) {
if ($handler instanceof UcAddressesDefaultAddressFieldHandler) {
// Bypass fill in values for marking it as the default.
continue;
}
if (isset($values[$fieldname])) {
// The value is already set. Do not override it.
continue;
}
if (array_key_exists($fieldname, $values) && is_null($values[$fieldname])) {
// Fields that are set to NULL should be skipped.
unset($values[$fieldname]);
continue;
}
// Check if the field is enabled an that it is used in the context.
if ($handler
->isFieldEnabled() && $handler
->checkContext()) {
// Fill in a value.
$values[$fieldname] = self::generateAddressFieldValue($fieldname, $values);
}
}
// Prefix values and add parents.
foreach ($values as $fieldname => $value) {
// Set in parents if needed.
$formfieldname = $prefix . $fieldname;
if ($parent_string) {
$formfieldname = $parent_string . '[' . $formfieldname . ']';
}
$form_values[$formfieldname] = $value;
}
return array(
'form_values' => $form_values,
'values' => $values,
);
}