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
- Implement a field with a non-existing handler.
- 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.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | uc_addresses6-missing-handler-1871916-5.patch | 5.9 KB | megachriz |
| #3 | uc_addresses-missing-handler-1871916-3.patch | 6.2 KB | megachriz |
| #1 | uc_addresses-broken-handler-exception-1871916-1.patch | 1.33 KB | megachriz |
Comments
Comment #1
megachrizThis patch introduces the UcAddressesBrokenHandlerException and throws it in UcAddressesSchemaAddress when the handler couldn't be found.
Comment #2
megachrizThink 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.
Comment #3
megachrizThe 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.
Comment #4
megachrizCommitted #3:
http://drupalcode.org/project/uc_addresses.git/commit/1d85d9e
Needs backport to the 6.x-2.x version.
Comment #5
megachrizPatch 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.
Comment #6
megachrizCommitted #5:
http://drupalcode.org/project/uc_addresses.git/commit/ae959a4
Setting issue version back to the version the issue was originally reported for.