You are here

function hook_uc_addresses_fields in Ubercart Addresses 6.2

Same name and namespace in other branches
  1. 7 uc_addresses.api.php \hook_uc_addresses_fields()

This hook allows you to register extra fields to be used in all address edit forms.

For a working example, look at uc_addresses_uc_addresses_fields() in the file uc_addresses.uc_addresses_fields.inc.

Return value

array An associative array containing:

  • title: the title of the field, safe for output.
  • type: (optional) The data type of the property.
  • handler: handler class, registered through hook_uc_addresses_field_handlers().
  • display_settings: (optional) An array of contexts to show or hide the field on:

    • default: boolean, if it may be displayed by default.
    • address_form: boolean, if it may be displayed on the address edit form.
    • address_view: boolean, if it may be displayed on the address book page.
    • checkout_form: boolean, if it may be displayed on the checkout page.
    • checkout_review: boolean, if it may be displayed on the checkout review page.
    • order_form: boolean, if it may be displayed on the order edit page.
    • order_view: boolean, if it may be displayed on order view pages.

    Adding display settings to the field definition is optional. If you don't set this, assumed is that the field may be showed everywhere.

  • compare: (optional) boolean, may this field be used in address comparisons? An address comparison is done to avoid having double addresses in the address book.

Optionally you can define extra properties in the definition. Properties can be reached from within the handler by calling getProperty(). When a handler uses extra properties, these properties will be required. Check the documentation of the handler to see which extra properties it requires.

See also

hook_uc_addresses_field_handlers()

3 functions implement hook_uc_addresses_fields()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

uc_addresses_example_uc_addresses_fields in uc_addresses_example/uc_addresses_example.module
Implements hook_uc_addresses_fields().
uc_addresses_test_uc_addresses_fields in tests/uc_addresses_test.module
Implements hook_uc_addresses_fields().
uc_addresses_uc_addresses_fields in ./uc_addresses.uc_addresses_fields.inc
Implementation of hook_uc_addresses_fields().
1 invocation of hook_uc_addresses_fields()
uc_addresses_get_address_fields in ./uc_addresses.module
Returns all fields registered by hook_uc_addresses_fields().

File

./uc_addresses.api.php, line 82
These hooks are invoked by the Ubercart Addresses module. @todo more documentation needed for hook_uc_addresses_field_handlers(). @todo Document the rest of the API.

Code

function hook_uc_addresses_fields() {

  // Example: register my own field.
  return array(
    'myfield' => array(
      'title' => t('My field'),
      'type' => 'text',
      'handler' => 'MyCustomFieldHandler',
      'display_settings' => array(
        'default' => TRUE,
        // Display it by default.
        'address_form' => TRUE,
        // Display it on the address edit form.
        'address_view' => TRUE,
        // Display it in the address book.
        'checkout_form' => FALSE,
        // Don't display during checkout.
        'checkout_review' => FALSE,
        // Don't display at checkout review.
        'order_form' => TRUE,
        // Display on order edit forms.
        'order_view' => TRUE,
      ),
      'compare' => TRUE,
    ),
  );
}