This a subissue of #1831424: Turn Ubercart Addresses address into an entity.
Problem/Motivation
The Entity API module provides a hook called hook_entity_property_info()
with which metadata about entity properties can be defined. Ubercart Addresses provides the hook hook_uc_addresses_fields()
with which address fields can be registered. As each address field of an address is essentially a property of the upcoming address entity, it would be nice if property metadata can be defined in hook_uc_addresses_fields()
, so modules that register address fields don't need to implement hook_entity_property_info()
as well to define additional or similar information about their fields.
One metadata item is the data type of the field, simply called 'type'. This can be 'text', 'integer', 'boolean', etc. So, in preparation of the entity integration, it would be nice if the data type is declared for each field, which will fallback to 'text' for if it's not defined.
Affected versions
Though it would only have a function for the 7.x-1.x version, fields specifying their data types will also be implemented for the 6.x-2.x version for consistency (and the information *could* be useful for modules extending Ubercart Addresses as well).
Conflicts
The Ubercart Addresses Example module already used the 'type' property to define the database data type. The example module should be adjusted to remain compatible with future changes (Entity API integration).
Proposed resolution
Current registered address fields will get an extra property called 'type'. This will be mapped to Entity API property info later on. Optionally, other properties could be defined as documented by hook_entity_property_info()
.
Remaining tasks
- Define data types for each registered address field that should not be just text.
- Provide the default value 'text' for property 'type' in
uc_addresses_get_address_fields()
. Adjust Ubercart Addresses Example module.Fixed in #1911136: Ubercart Addresses Example module: separate schema definitions from field handler API definitions.
User interface changes
None.
API changes
Modules registering address fields should from now on define the data type of their fields if it's not supposed to be just text. Optionally, they can define other properties as documented by hook_entity_property_info()
.
I'm working on it.
Comment | File | Size | Author |
---|---|---|---|
#7 | uc_addresses6-field-data-types-1910626-7.patch | 7.02 KB | MegaChriz |
#5 | uc_addresses-field-data-types-1910626-5.patch | 10.78 KB | MegaChriz |
#3 | uc_addresses-field-data-types-1910626-3.patch | 9.75 KB | MegaChriz |
#1 | uc_addresses-field-data-types-1910626-1.patch | 4.95 KB | MegaChriz |
Comments
Comment #1
MegaChriz CreditAttribution: MegaChriz commentedFirst patch. This patch defines data types for each registered address field, plus it adjusts and cleans up
uc_addresses_get_address_fields()
. The example module is not adjusted yet. And it should be documented that data received withhook_uc_addresses_fields()
will be passed tohook_entity_property_info()
.Comment #2
MegaChriz CreditAttribution: MegaChriz commentedI've opened a separate issue for the problems in the example module: #1911136: Ubercart Addresses Example module: separate schema definitions from field handler API definitions. as these problems have less to do with the task itself.
Comment #3
MegaChriz CreditAttribution: MegaChriz commentedNew patch. This patch adds some extra documentation and also sets a default for the "label" property for each field. The label is used by Entity API and visible in Rules (for example).
I think this one is good to go.
Comment #5
MegaChriz CreditAttribution: MegaChriz commentedIn addition of the patch in #3, this patch makes a change in the entity tests. These tests still expected a property called 'uid' of type 'integer', while the property was replaced by a property called 'user'. On http://drupal.org/node/1021466 it is advised to not use 'uid' as property, but use 'user' instead.
Comment #6
MegaChriz CreditAttribution: MegaChriz commentedCommitted #5.
Needs backport to 6.x-2.x.
Comment #7
MegaChriz CreditAttribution: MegaChriz commentedBackport of the patch posted in #5. Note that Entity API related code is not included, because there is no Entity API for Drupal 6. The properties 'label' and 'options list' in field definitions are not backported, because these are only relevant to Entity API. The 'type' property could be useful in future enhancements.
Comment #8
MegaChriz CreditAttribution: MegaChriz commentedCommitted #7.
Setting issue back to the version it was originally reported for and mark it as fixed.
Comment #9.0
(not verified) CreditAttribution: commentedMarked adjustment for example module as done.