/** * Gets the address values used to build the view. * * @param AddressInterface $address The address. * @param AddressFormatInterface $addressFormat The address format. * * @return array The values, keyed by address field. */ protected function getValues(AddressInterface $address, AddressFormatInterface $addressFormat) { $values = []; foreach (AddressField::getAll() as $field) { $getter = 'get' . ucfirst($field); $values[$field] = $address->{$getter}(); } // Replace the subdivision values with the names of any predefined ones. foreach ($addressFormat->getUsedSubdivisionFields() as $field) { if (empty($values[$field])) { // This level is empty, so there can be no sublevels. break; } $subdivision = $this->subdivisionRepository->get($values[$field], $address->getLocale()); if (!$subdivision) { // This level has no predefined subdivisions, stop. break; } $values[$field] = $subdivision->getCode(); if (!$subdivision->hasChildren()) { // The current subdivision has no children, stop. break; } } return $values; }