Problem/Motivation

Modules can define their own address fields for Ubercart Addresses by implementing hook_uc_addresses_fields(). Each field needs a handler as described the documentation about the field handler API.
When for some reason the handler is not available, the following PHP fatal error could occur:

Fatal error: Class name must be a valid object or a string in /Websites/drupal/drupalsites/drupal7/sites/all/modules/contrib/uc_addresses/class/UcAddressesSchemaAddress.class.php on line 79

It would be better to replace this with a more descriptive error message.

How to reproduce

  1. Implement a field with a non-existing handler.
  2. Go to a page that's using address fields, for example the address book (user/1/addresses).

Example: a field with a non-existing handler (taken from uc_addresses.api.php):

/**
 * Implements hook_uc_addresses_fields().
 */
function mymodule_uc_addresses_fields() {
  // Example: register my own field
  return array(
    'myfield' => array(
      'title' => t('My field'),
      '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, // Display on order view pages
      ),
      'compare' => TRUE, // Field is used in address comparisons
    ),
  );
}

Affected versions

7.x-1.x and 6.x-2.x.

Proposed resolution

Prevent the PHP fatal error and throw and exception instead. Call the exception an UcAddressesBrokenHandlerException.

Remaining tasks

  • Provide a patch that implements the proposed resolution.

User interface changes

Instead of PHP fatal error, a more descriptive error message will be displayed.

API changes

There will be a new Exception class: UcAddressesBrokenHandlerException.

I'm working on a fix.

Comments

megachriz’s picture

Status: Active » Needs review
StatusFileSize
new1.33 KB

This patch introduces the UcAddressesBrokenHandlerException and throws it in UcAddressesSchemaAddress when the handler couldn't be found.

megachriz’s picture

Status: Needs review » Needs work

Think about it again, there are more places where field handlers are loaded. It may be better to handle this is in a central place.

I'm working on a different fix.

megachriz’s picture

Status: Needs work » Needs review
StatusFileSize
new6.2 KB

The following patch is inspired by how Feeds handles a similar problem like this. The patch introduces a new handler for when a handler is missing: UcAddressesMissingFieldHandler. The field will get this handler if the original handler is missing.

megachriz’s picture

Version: 7.x-1.x-dev » 6.x-2.x-dev
Status: Needs review » Patch (to be ported)

Committed #3:
http://drupalcode.org/project/uc_addresses.git/commit/1d85d9e

Needs backport to the 6.x-2.x version.

megachriz’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new5.9 KB

Patch for the 6.x-2.x version. This is nearly the same as the patch in #3. Let's see of this passes the automated tests.

megachriz’s picture

Version: 6.x-2.x-dev » 7.x-1.x-dev
Status: Needs review » Fixed

Committed #5:
http://drupalcode.org/project/uc_addresses.git/commit/ae959a4

Setting issue version back to the version the issue was originally reported for.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.