You are here

function hook_uc_addresses_fields in Ubercart Addresses 7

Same name and namespace in other branches
  1. 6.2 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.
  • (additional data used by Entity API, see hook_entity_property_info().)

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.

Since each field is also a property of the uc_addresses entity, the definition for each field will also be passed to Entity API as metadata. This means that implementing hook_entity_property_info() separately to define additional (or similar) information about your field is not needed. Your field will automatically become available in Rules, for example. However, you may need to define extra properties for your field in order to let it operate properly in entity related functionalities. Check the documentation of hook_entity_property_info() to see which extra properties you can define.

See also

hook_uc_addresses_field_handlers()

hook_entity_property_info()

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
Implements 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 94
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,
    ),
  );
}