Tips and Tricks

Last updated on
30 April 2025

Addressfield Tips

Some RETS feeds separate the street address into many parts, however there is no way to really map them to the street portion of Addressfield, the following code snippet is a handy work around to this problem.

This uses the hook_drealty_import_presave_alter hook, it has two arguments:

  • $item: this is the entity that is about to be saved any changes to this entity will be persisted to the underlying storage mechanism.
  • $item_context: this is an array of contextual data from the import process and has the following keys.
    • field_mappings - an array of the current field mappings which is an array of the RETS systemnames keyed by field names
    • connection - the current drealty connection object [DrealtyConnection]
    • resource - the current drealty resource object [DrealtyRetsResource]
    • key_field - the key field for the current class
    • rets_item - the current RETS data that is being processed, data is keyed by the RETS SystemName
   function mymodule_drealty_import_presave_alter(&$item, $item_context) {
     // limit the function to only operate on listings (this could be improved, i'm using the bundle 'residential' to limit/filter on)
     if($item->type == 'residential') {
        // in this case my addressfield field is named field_address
        // the RETS feed provides the street address in two parts StreetNumber and StreetName 
        $item->field_address[LANGUAGE_NONE][0]['thoroughfare'] = $item_context['rets_item']['StreetNumber'] . ' ' . $item_context['rets_item']['StreetName'];
     }
   }

Help improve this page

Page status: Not set

You can: