modules/acm/src/Element/AcmAddress.php
public static function calculateDynamicParts($country) {
    $dynamic_parts = [];
    $addressFormatRepository = \Drupal::service('address.address_format_repository');
    $address_format = $addressFormatRepository->get($country);
    $subdivisionRepository = \Drupal::service('address.subdivision_repository');
    $options = $subdivisionRepository->getList([$country]);
    $labels = LabelHelper::getFieldLabels($address_format);

    // Update region options based on country.
    $dynamic_parts['region']['#options'] = $options;
    $dynamic_parts['region']['#required'] = TRUE;
    $dynamic_parts['region']['#access'] = TRUE;

    // Update labels.
    $cityLabel = $labels['locality'];
    $postcodeLabel = $labels['postalCode'];
    $regionLabel = $labels['administrativeArea'];
    $dynamic_parts['region']['#title'] = $regionLabel;
    $dynamic_parts['postcode']['#title'] = $postcodeLabel;
    $dynamic_parts['city']['#title'] = $cityLabel;

    if (empty($cityLabel)) {
      $dynamic_parts['city']['#required'] = FALSE;
      $dynamic_parts['city']['#access'] = FALSE;
    }

    if (empty($postcodeLabel)) {
      $dynamic_parts['postcode']['#required'] = FALSE;
      $dynamic_parts['postcode']['#access'] = FALSE;
    }

    if (empty($regionLabel) || empty($options)) {
      $dynamic_parts['region']['#required'] = FALSE;
      $dynamic_parts['region']['#access'] = FALSE;
    }

    return $dynamic_parts;
  }
public static function calculateDynamicParts($country) {
    $dynamic_parts = [];
    $addressFormatRepository = \Drupal::service('address.address_format_repository');
    $address_format = $addressFormatRepository->get($country);
    $subdivisionRepository = \Drupal::service('address.subdivision_repository');
    $options = $subdivisionRepository->getList([$country]);
    $labels = LabelHelper::getFieldLabels($address_format);

    // Update region options based on country.
    $dynamic_parts['region']['#options'] = $options;
    $dynamic_parts['region']['#required'] = TRUE;
    $dynamic_parts['region']['#access'] = TRUE;

    // Update labels.
    $cityLabel = $labels['locality'];
    $postcodeLabel = $labels['postalCode'];
    $regionLabel = $labels['administrativeArea'];
    $dynamic_parts['region']['#title'] = $regionLabel;
    $dynamic_parts['postcode']['#title'] = $postcodeLabel;
    $dynamic_parts['city']['#title'] = $cityLabel;

    if (empty($cityLabel)) {
      $dynamic_parts['city']['#required'] = FALSE;
      $dynamic_parts['city']['#access'] = FALSE;
    }

    if (empty($postcodeLabel)) {
      $dynamic_parts['postcode']['#required'] = FALSE;
      $dynamic_parts['postcode']['#access'] = FALSE;
    }

    if (empty($regionLabel) || empty($options)) {
      $dynamic_parts['region']['#required'] = FALSE;
      $dynamic_parts['region']['#access'] = FALSE;
    }

    return $dynamic_parts;
  }
public static function calculateDynamicParts ( $ country ) { $ dynamic_parts = [ ] ; $ addressFormatRepository = \ Drupal :: service ( 'address.address_format_repository' ) ; $ address_format = $ addressFormatRepository -> get ( $ country ) ; $ subdivisionRepository = \ Drupal :: service ( 'address.subdivision_repository' ) ; $ options = $ subdivisionRepository -> getList ( [ $ country ] ) ; $ labels = LabelHelper :: getFieldLabels ( $ address_format ) ; // Update region options based on country. $ dynamic_parts [ 'region' ] [ '#options' ] = $ options ; $ dynamic_parts [ 'region' ] [ '#required' ] = TRUE ; $ dynamic_parts [ 'region' ] [ '#access' ] = TRUE ; // Update labels. $ cityLabel = $ labels [ 'locality' ] ; $ postcodeLabel = $ labels [ 'postalCode' ] ; $ regionLabel = $ labels [ 'administrativeArea' ] ; $ dynamic_parts [ 'region' ] [ '#title' ] = $ regionLabel ; $ dynamic_parts [ 'postcode' ] [ '#title' ] = $ postcodeLabel ; $ dynamic_parts [ 'city' ] [ '#title' ] = $ cityLabel ; if ( empty ( $ cityLabel ) ) { $ dynamic_parts [ 'city' ] [ '#required' ] = FALSE ; $ dynamic_parts [ 'city' ] [ '#access' ] = FALSE ; } if ( empty ( $ postcodeLabel ) ) { $ dynamic_parts [ 'postcode' ] [ '#required' ] = FALSE ; $ dynamic_parts [ 'postcode' ] [ '#access' ] = FALSE ; } if ( empty ( $ regionLabel ) || empty ( $ options ) ) { $ dynamic_parts [ 'region' ] [ '#required' ] = FALSE ; $ dynamic_parts [ 'region' ] [ '#access' ] = FALSE ; } return $ dynamic_parts ; }
Calculate dynamic address parts per country.

@param string $country
Country code.

@return array
Calculated dynamic form parts.
Calculate dynamic address parts per country .