Posted by bojanz on February 4, 2012 at 2:03pm
5 followers
| Project: | Drupal Commerce |
| Version: | 7.x-1.x-dev |
| Component: | Customer |
| Category: | task |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
| Issue tags: | 1.3 review |
Issue Summary
Currently there is no label callback for customer profiles:
<?php
'label' => 'profile_id', // TODO: Update to use a custom callback.
?>We can agree that just getting the id is not exactly useful, which is why commerce_addressbook invents its own label logic, and even provides its own alter function:
#1425784: Add ability to alter dropdown label.
So let's have a callback in Commerce that returns the "thoroughfare" value (street, basically) of the address.
Comments
#1
Simple patch.
Might want to use wrapper instead (for code style), since this is the first usage of field_get_items() in commerce code ;)
#2
We'll need a fallback in the event that a customer profile type does not have an address field. Perhaps we can implement this callback as an abstraction layer between a per customer profile type callback. The default callback can check for an addressfield and use its label and fallback to the profile ID if no addressfield is found. Then of course any other module can implement an alternate callback.
#3
So perhaps in the "bundle" array have a "bundle label callback" key, and have our label callback call the "bundle label callback" function if it exists, and if not, just return the profile_id. A bundle-level label callback always knows which data it has and what it should use.
Not sure if it's perhaps a bit overcomplicated.
#4
I tried to implement what Ryan said in #2.
So what did I do?
* I set the default callback on the profile type on generation (but it can be deleted through alter)
* I created a label callback that will try to get the label callback from the profile type and fallback to a default callback.
* Created the default callback that will try to get the street from the address field, if empty of the addressfield doesn't exist, it returns the profile id instead.
Tested with all cases I could image, (no address field, addressfield with no address and addressfield with address) and works great.
#5
Tagging.
#6
This is pretty straight forward and looks ready to commit to me. I tried to break it, but I couldn't :P
#7
I added docs for this to commerce_customer.api.php, and I don't see any reason not to go with name_line for the label. It may be open to collisions, but it's at least more useful than the street address. Committed! Thanks all.
#8
Automatically closed -- issue fixed for 2 weeks with no activity.