You are here

function uc_addresses_get_address_field_handler in Ubercart Addresses 6.2

Same name and namespace in other branches
  1. 7 uc_addresses.module \uc_addresses_get_address_field_handler()

Returns a specific handler instance of a field.

Parameters

UcAddressesSchemaAddress $address: An address object.

string $fieldname: The field name to get a handler for.

string $context: The context where the fields are used for.

Return value

UcAddressesFieldHandler An instance of UcAddressesFieldHandler if the handler was found. An instance of UcAddressesMissingFieldHandler otherwise.

2 calls to uc_addresses_get_address_field_handler()
UcAddressesSchemaAddress::getHandler in class/UcAddressesSchemaAddress.class.php
Returns a handler instance.
uc_addresses_get_address_field_handler_instances in ./uc_addresses.module
Returns all handler instances of fields registered by hook_uc_addresses_fields().
1 string reference to 'uc_addresses_get_address_field_handler'
UcAddressesSchemaAddress::getHandler in class/UcAddressesSchemaAddress.class.php
Returns a handler instance.

File

./uc_addresses.module, line 906
Adds user profile address support to Ubercart.

Code

function uc_addresses_get_address_field_handler(UcAddressesSchemaAddress $address, $fieldname, $context = 'default') {
  ctools_include('plugins');
  ctools_plugin_api_include('uc_addresses', 'uc_addresses_fields', 2, 2);
  $fields_data = uc_addresses_get_address_fields();
  try {
    if (isset($fields_data[$fieldname])) {
      $class = ctools_plugin_load_class('uc_addresses', 'field_handlers', $fields_data[$fieldname]['handler'], 'handler');
      if ($class) {
        return new $class($fieldname, $address, $context);
      }

      // Handler not found.
      $args = array(
        '%handler' => $fields_data[$fieldname]['handler'],
        '%field' => $fieldname,
      );
      if (user_access('administer store')) {
        drupal_set_message(t('Missing Ubercart Addresses field handler %handler for field %field. Check whether all required libraries and modules are installed properly.', $args), 'error', FALSE);
      }
      else {
        drupal_set_message(t('Missing Ubercart Addresses field handler %handler for field %field. Please contact your site administrator.', $args), 'error', FALSE);
      }
    }
  } catch (UcAddressesIncompatibleHandlerException $e) {

    // Ignore incompatible handlers.
  }

  // Return an instance of UcAddressesMissingFieldHandler instead.
  $class = ctools_plugin_load_class('uc_addresses', 'field_handlers', 'UcAddressesMissingFieldHandler', 'handler');
  return new $class($fieldname, $address, $context);
}