You are here

function uc_addresses_get_address_field_handler in Ubercart Addresses 7

Same name and namespace in other branches
  1. 6.2 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.

4 calls to uc_addresses_get_address_field_handler()
FeedsUcAddressesProcessor::setTargetElement in feeds/FeedsUcAddressesProcessor.inc
Override setTargetElement to operate on a target item that is an address.
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().
uc_addresses_tokens in ./uc_addresses.tokens.inc
Implements hook_tokens().
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 1423
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);
}