You are here

function _address_update_entity in Address 8

Updates the given entity's field for the RC1 changes.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity.

string $field_name: The name of the field to update.

1 call to _address_update_entity()
address_post_update_convert_names_subdivisions in ./address.post_update.php
Re-save all entities with address data to update names and subdivisions.

File

./address.module, line 65
Provides functionality for handling postal addresses.

Code

function _address_update_entity(EntityInterface $entity, $field_name) {
  $update_helper = '\\CommerceGuys\\Addressing\\UpdateHelper';
  foreach ($entity->{$field_name} as $delta => $address) {
    $names = $update_helper::splitRecipient($address->given_name, $address->country_code);
    $address->given_name = $names['givenName'];
    $address->family_name = $names['familyName'];

    // Now update the subdivisions.
    $address->administrative_area = $update_helper::updateSubdivision($address->administrative_area);
    $address->locality = $update_helper::updateSubdivision($address->locality);
    $address->dependent_locality = $update_helper::updateSubdivision($address->dependent_locality);
  }
}