/**
  * Gets the address values used for rendering.
  *
  * @param \Drupal\address\AddressInterface $address
  *   The address.
  * @param \Drupal\address\Entity\AddressFormatInterface $address_format
  *   The address format.
  *
  * @return array
  *   The values, keyed by address field.
  */
 protected function getValues(AddressInterface $address, AddressFormatInterface $address_format)
 {
     $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 ($address_format->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;
 }
 /**
  * Gets the address values used for rendering.
  *
  * @param \Drupal\address\AddressInterface $address
  *   The address.
  * @param \Drupal\address\Entity\AddressFormatInterface $address_format
  *   The address format.
  *
  * @return array
  *   The values, keyed by address field.
  */
 protected function getValues(AddressInterface $address, AddressFormatInterface $address_format)
 {
     $values = [];
     foreach (AddressField::getAll() as $field) {
         $getter = 'get' . ucfirst($field);
         $values[$field] = $address->{$getter}();
     }
     foreach ($address_format->getUsedSubdivisionFields() as $field) {
         $value = $values[$field];
         // The template needs access to both the subdivision code and name.
         $values[$field] = ['code' => '', 'name' => $value];
         if (empty($value)) {
             // This level is empty, so there can be no sublevels.
             break;
         }
         $subdivision = $this->subdivisionRepository->get($value, $address->getLocale());
         if (!$subdivision) {
             // This level has no predefined subdivisions, stop.
             break;
         }
         // Replace the subdivision values with the predefined ones.
         $values[$field] = ['code' => $subdivision->getCode(), 'name' => $subdivision->getName()];
         if (!$subdivision->hasChildren()) {
             // The current subdivision has no children, stop.
             break;
         }
     }
     return $values;
 }