Commit c8a4d1f2 authored by Joël Pittet's avatar Joël Pittet Committed by Bojan Živanović
Browse files

Issue #2507665 by joelpittet: addressfield_get_administrative_areas calls t()...

Issue #2507665 by joelpittet: addressfield_get_administrative_areas calls t() nearly 1000 times in one call
parent ab2dbabe
Loading
Loading
Loading
Loading
+19 −4
Original line number Diff line number Diff line
@@ -11,6 +11,24 @@
 *   NULL if not found.
 */
function addressfield_get_administrative_areas($country_code) {
  // Maintain a static cache to avoid passing the administrative areas through
  // t() more than once per request.
  $administrative_areas = &drupal_static(__FUNCTION__, array());
  if (empty($administrative_areas)) {
    // Get the default administrative areas.
    $administrative_areas = _addressfield_get_administrative_areas_defaults();

    // Allow other modules to alter the administrative areas.
    drupal_alter('addressfield_administrative_areas', $administrative_areas);
  }

  return isset($administrative_areas[$country_code]) ? $administrative_areas[$country_code] : NULL;
}

/**
 * Provides the default administrative areas.
 */
function _addressfield_get_administrative_areas_defaults() {
  // To avoid needless pollution of the strings list we only pass to t()
  // those administrative areas that are in English (or a latin transcription),
  // and belong to a country that either has multiple official languages (CA)
@@ -1032,8 +1050,5 @@ function addressfield_get_administrative_areas($country_code) {
    'V' => 'Zulia',
  );

  // Allow other modules to alter the administrative areas.
  drupal_alter('addressfield_administrative_areas', $administrative_areas);

  return isset($administrative_areas[$country_code]) ? $administrative_areas[$country_code] : null;
  return $administrative_areas;
}