From d31424f228b950bd6c200c70ddf9f74cdf02fa3e Mon Sep 17 00:00:00 2001 From: Christian Burk <766573+omahane@users.noreply.github.com> Date: Mon, 9 Dec 2024 16:14:32 -0600 Subject: [PATCH 1/8] VACMS-19227: Adds Philippines as a US state for facility purposes, not political ones --- .../ManilaAddPhilippinesStateSubscriber.php | 441 ++++++++++++++++++ .../va_gov_manila/va_gov_manila.services.yml | 5 +- 2 files changed, 445 insertions(+), 1 deletion(-) create mode 100644 docroot/modules/custom/va_gov_manila/src/EventSubscriber/ManilaAddPhilippinesStateSubscriber.php diff --git a/docroot/modules/custom/va_gov_manila/src/EventSubscriber/ManilaAddPhilippinesStateSubscriber.php b/docroot/modules/custom/va_gov_manila/src/EventSubscriber/ManilaAddPhilippinesStateSubscriber.php new file mode 100644 index 0000000000..54292ef562 --- /dev/null +++ b/docroot/modules/custom/va_gov_manila/src/EventSubscriber/ManilaAddPhilippinesStateSubscriber.php @@ -0,0 +1,441 @@ +getDefinition(); + if ($definition['country_code'] == 'US') { + $definition['format'] = $definition['format'] . "\n%administrativeArea"; + $definition['administrative_area_type'] = AdministrativeAreaType::STATE; + $definition['subdivision_depth'] = 1; + $event->setDefinition($definition); + } + } + + /** + * Provides the states of the US (plus the Philippines). + * + * @param \Drupal\address\Event\SubdivisionsEvent $event + * The subdivisions event. + */ + public function onSubdivisions(SubdivisionsEvent $event) { + $parents = $event->getParents(); + if ($event->getParents() != ['US']) { + return; + } + + $definitions = [ + 'country_code' => $parents[0], + 'parents' => $parents, + 'subdivisions' => [ + 'AL' => [ + 'code' => 'AL', + 'name' => 'Alabama', + 'country_code' => 'US', + 'id' => 'AL', + ], + 'AK' => [ + 'code' => 'AK', + 'name' => 'Alaska', + 'country_code' => 'US', + 'id' => 'AK', + ], + 'AS' => [ + 'code' => 'AS', + 'name' => 'American Samoa', + 'country_code' => 'US', + 'id' => 'AS', + ], + 'AZ' => [ + 'code' => 'AZ', + 'name' => 'Arizona', + 'country_code' => 'US', + 'id' => 'AZ', + ], + 'AR' => [ + 'code' => 'AR', + 'name' => 'Arkansas', + 'country_code' => 'US', + 'id' => 'AR', + ], + 'AA' => [ + 'code' => 'AA', + 'name' => 'Armed Forces (AA)', + 'country_code' => 'US', + 'id' => 'AA', + ], + 'AE' => [ + 'code' => 'AE', + 'name' => 'Armed Forces (AE)', + 'country_code' => 'US', + 'id' => 'AE', + ], + 'AP' => [ + 'code' => 'AP', + 'name' => 'Armed Forces (AP)', + 'country_code' => 'US', + 'id' => 'AP', + ], + 'CA' => [ + 'code' => 'CA', + 'name' => 'California', + 'country_code' => 'US', + 'id' => 'CA', + ], + 'CO' => [ + 'code' => 'CO', + 'name' => 'Colorado', + 'country_code' => 'US', + 'id' => 'CO', + ], + 'CT' => [ + 'code' => 'CT', + 'name' => 'Connecticut', + 'country_code' => 'US', + 'id' => 'CT', + ], + 'DE' => [ + 'code' => 'DE', + 'name' => 'Delaware', + 'country_code' => 'US', + 'id' => 'DE', + ], + 'DC' => [ + 'code' => 'DC', + 'name' => 'District of Columbia', + 'country_code' => 'US', + 'id' => 'DC', + ], + 'FL' => [ + 'code' => 'FL', + 'name' => 'Florida', + 'country_code' => 'US', + 'id' => 'FL', + ], + 'GA' => [ + 'code' => 'GA', + 'name' => 'Georgia', + 'country_code' => 'US', + 'id' => 'GA', + ], + 'GU' => [ + 'code' => 'GU', + 'name' => 'Guam', + 'country_code' => 'US', + 'id' => 'GU', + ], + 'HI' => [ + 'code' => 'HI', + 'name' => 'Hawaii', + 'country_code' => 'US', + 'id' => 'HI', + ], + 'ID' => [ + 'code' => 'ID', + 'name' => 'Idaho', + 'country_code' => 'US', + 'id' => 'ID', + ], + 'IL' => [ + 'code' => 'IL', + 'name' => 'Illinois', + 'country_code' => 'US', + 'id' => 'IL', + ], + 'IN' => [ + 'code' => 'IN', + 'name' => 'Indiana', + 'country_code' => 'US', + 'id' => 'IN', + ], + 'IA' => [ + 'code' => 'IA', + 'name' => 'Iowa', + 'country_code' => 'US', + 'id' => 'IA', + ], + 'KS' => [ + 'code' => 'KS', + 'name' => 'Kansas', + 'country_code' => 'US', + 'id' => 'KS', + ], + 'KY' => [ + 'code' => 'KY', + 'name' => 'Kentucky', + 'country_code' => 'US', + 'id' => 'KY', + ], + 'LA' => [ + 'code' => 'LA', + 'name' => 'Louisiana', + 'country_code' => 'US', + 'id' => 'LA', + ], + 'ME' => [ + 'code' => 'ME', + 'name' => 'Maine', + 'country_code' => 'US', + 'id' => 'ME', + ], + 'MH' => [ + 'code' => 'MH', + 'name' => 'Marshall Islands', + 'country_code' => 'US', + 'id' => 'MH', + ], + 'MD' => [ + 'code' => 'MD', + 'name' => 'Maryland', + 'country_code' => 'US', + 'id' => 'MD', + ], + 'MA' => [ + 'code' => 'MA', + 'name' => 'Massachusetts', + 'country_code' => 'US', + 'id' => 'MA', + ], + 'MI' => [ + 'code' => 'MI', + 'name' => 'Michigan', + 'country_code' => 'US', + 'id' => 'MI', + ], + 'FM' => [ + 'code' => 'FM', + 'name' => 'Micronesia', + 'country_code' => 'US', + 'id' => 'FM', + ], + 'MN' => [ + 'code' => 'MN', + 'name' => 'Minnesota', + 'country_code' => 'US', + 'id' => 'MN', + ], + 'MS' => [ + 'code' => 'MS', + 'name' => 'Mississippi', + 'country_code' => 'US', + 'id' => 'MS', + ], + 'MO' => [ + 'code' => 'MO', + 'name' => 'Missouri', + 'country_code' => 'US', + 'id' => 'MO', + ], + 'MT' => [ + 'code' => 'MT', + 'name' => 'Montana', + 'country_code' => 'US', + 'id' => 'MT', + ], + 'NE' => [ + 'code' => 'NE', + 'name' => 'Nebraska', + 'country_code' => 'US', + 'id' => 'NE', + ], + 'NV' => [ + 'code' => 'NV', + 'name' => 'Nevada', + 'country_code' => 'US', + 'id' => 'NV', + ], + 'NH' => [ + 'code' => 'NH', + 'name' => 'New Hampshire', + 'country_code' => 'US', + 'id' => 'NH', + ], + 'NJ' => [ + 'code' => 'NJ', + 'name' => 'New Jersey', + 'country_code' => 'US', + 'id' => 'NJ', + ], + 'NM' => [ + 'code' => 'NM', + 'name' => 'New Mexico', + 'country_code' => 'US', + 'id' => 'NM', + ], + 'NY' => [ + 'code' => 'NY', + 'name' => 'New York', + 'country_code' => 'US', + 'id' => 'NY', + ], + 'NC' => [ + 'code' => 'NC', + 'name' => 'North Carolina', + 'country_code' => 'US', + 'id' => 'NC', + ], + 'ND' => [ + 'code' => 'ND', + 'name' => 'North Dakota', + 'country_code' => 'US', + 'id' => 'ND', + ], + 'MP' => [ + 'code' => 'MP', + 'name' => 'Northern Mariana Islands', + 'country_code' => 'US', + 'id' => 'MP', + ], + 'OH' => [ + 'code' => 'OH', + 'name' => 'Ohio', + 'country_code' => 'US', + 'id' => 'OH', + ], + 'OK' => [ + 'code' => 'OK', + 'name' => 'Oklahoma', + 'country_code' => 'US', + 'id' => 'OK', + ], + 'OR' => [ + 'code' => 'OR', + 'name' => 'Oregon', + 'country_code' => 'US', + 'id' => 'OR', + ], + 'PW' => [ + 'code' => 'PW', + 'name' => 'Palau', + 'country_code' => 'US', + 'id' => 'PW', + ], + 'PA' => [ + 'code' => 'PA', + 'name' => 'Pennsylvania', + 'country_code' => 'US', + 'id' => 'PA', + ], + 'PH' => [ + 'code' => 'PH', + 'name' => 'Philippines', + 'country_code' => 'US', + 'id' => 'PH', + ], + + 'PR' => [ + 'code' => 'PR', + 'name' => 'Puerto Rico', + 'country_code' => 'US', + 'id' => 'PR', + ], + 'RI' => [ + 'code' => 'RI', + 'name' => 'Rhode Island', + 'country_code' => 'US', + 'id' => 'RI', + ], + 'SC' => [ + 'code' => 'SC', + 'name' => 'South Carolina', + 'country_code' => 'US', + 'id' => 'SC', + ], + 'SD' => [ + 'code' => 'SD', + 'name' => 'South Dakota', + 'country_code' => 'US', + 'id' => 'SD', + ], + 'TN' => [ + 'code' => 'TN', + 'name' => 'Tennessee', + 'country_code' => 'US', + 'id' => 'TN', + ], + 'TX' => [ + 'code' => 'TX', + 'name' => 'Texas', + 'country_code' => 'US', + 'id' => 'TX', + ], + 'UT' => [ + 'code' => 'UT', + 'name' => 'Utah', + 'country_code' => 'US', + 'id' => 'UT', + ], + 'VT' => [ + 'code' => 'VT', + 'name' => 'Vermont', + 'country_code' => 'US', + 'id' => 'VT', + ], + 'VI' => [ + 'code' => 'VI', + 'name' => 'Virgin Islands', + 'country_code' => 'US', + 'id' => 'VI', + ], + 'VA' => [ + 'code' => 'VA', + 'name' => 'Virginia', + 'country_code' => 'US', + 'id' => 'VA', + ], + 'WA' => [ + 'code' => 'WA', + 'name' => 'Washington', + 'country_code' => 'US', + 'id' => 'WA', + ], + 'WV' => [ + 'code' => 'WV', + 'name' => 'West Virginia', + 'country_code' => 'US', + 'id' => 'WV', + ], + 'WI' => [ + 'code' => 'WI', + 'name' => 'Wisconsin', + 'country_code' => 'US', + 'id' => 'WI', + ], + 'WY' => [ + 'code' => 'WY', + 'name' => 'Wyoming', + 'country_code' => 'US', + 'id' => 'WY', + ], + ], + ]; + $event->setDefinitions($definitions); + } + +} diff --git a/docroot/modules/custom/va_gov_manila/va_gov_manila.services.yml b/docroot/modules/custom/va_gov_manila/va_gov_manila.services.yml index 03ea55b4eb..77a22e20be 100644 --- a/docroot/modules/custom/va_gov_manila/va_gov_manila.services.yml +++ b/docroot/modules/custom/va_gov_manila/va_gov_manila.services.yml @@ -4,4 +4,7 @@ services: arguments: ['@entity_type.manager', '@current_route_match', '@pathauto.generator', '@messenger'] tags: - { name: event_subscriber } - + va_gov_manila.manila_add_philippines_state_subscriber: + class: Drupal\va_gov_manila\EventSubscriber\ManilaAddPhilippinesStateSubscriber + tags: + - { name: event_subscriber } From 8ebb21d772ed08ed5e23f1e1528b35a980142f19 Mon Sep 17 00:00:00 2001 From: Christian Burk <766573+omahane@users.noreply.github.com> Date: Tue, 10 Dec 2024 11:51:56 -0600 Subject: [PATCH 2/8] VACMS-19227: Moves code to new module --- config/sync/core.extension.yml | 1 + .../EventSubscriber/AddPhilippinesAsStateSubscriber.php} | 4 ++-- .../modules/custom/va_gov_address/va_gov_address.info.yml | 7 +++++++ .../custom/va_gov_address/va_gov_address.services.yml | 5 +++++ .../custom/va_gov_manila/va_gov_manila.services.yml | 4 ---- 5 files changed, 15 insertions(+), 6 deletions(-) rename docroot/modules/custom/{va_gov_manila/src/EventSubscriber/ManilaAddPhilippinesStateSubscriber.php => va_gov_address/src/EventSubscriber/AddPhilippinesAsStateSubscriber.php} (98%) create mode 100644 docroot/modules/custom/va_gov_address/va_gov_address.info.yml create mode 100644 docroot/modules/custom/va_gov_address/va_gov_address.services.yml diff --git a/config/sync/core.extension.yml b/config/sync/core.extension.yml index db1349c19f..3a27a631da 100644 --- a/config/sync/core.extension.yml +++ b/config/sync/core.extension.yml @@ -253,6 +253,7 @@ module: upgrade_status: 0 user: 0 user_history: 0 + va_gov_address: 0 va_gov_api: 0 va_gov_backend: 0 va_gov_banner: 0 diff --git a/docroot/modules/custom/va_gov_manila/src/EventSubscriber/ManilaAddPhilippinesStateSubscriber.php b/docroot/modules/custom/va_gov_address/src/EventSubscriber/AddPhilippinesAsStateSubscriber.php similarity index 98% rename from docroot/modules/custom/va_gov_manila/src/EventSubscriber/ManilaAddPhilippinesStateSubscriber.php rename to docroot/modules/custom/va_gov_address/src/EventSubscriber/AddPhilippinesAsStateSubscriber.php index 54292ef562..9356583af3 100644 --- a/docroot/modules/custom/va_gov_manila/src/EventSubscriber/ManilaAddPhilippinesStateSubscriber.php +++ b/docroot/modules/custom/va_gov_address/src/EventSubscriber/AddPhilippinesAsStateSubscriber.php @@ -1,6 +1,6 @@ Date: Tue, 10 Dec 2024 12:13:44 -0600 Subject: [PATCH 3/8] Update va_gov_manila.services.yml --- docroot/modules/custom/va_gov_manila/va_gov_manila.services.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/docroot/modules/custom/va_gov_manila/va_gov_manila.services.yml b/docroot/modules/custom/va_gov_manila/va_gov_manila.services.yml index 4a39b1e3f8..03ea55b4eb 100644 --- a/docroot/modules/custom/va_gov_manila/va_gov_manila.services.yml +++ b/docroot/modules/custom/va_gov_manila/va_gov_manila.services.yml @@ -4,3 +4,4 @@ services: arguments: ['@entity_type.manager', '@current_route_match', '@pathauto.generator', '@messenger'] tags: - { name: event_subscriber } + From a21e95353b7de54af684cf948dadc34ae505e706 Mon Sep 17 00:00:00 2001 From: Christian Burk <766573+omahane@users.noreply.github.com> Date: Wed, 11 Dec 2024 08:49:56 -0600 Subject: [PATCH 4/8] VACMS-19227: Add all countries to press release --- ...field.node.press_release.field_address.yml | 263 +++++++++++++++++- 1 file changed, 261 insertions(+), 2 deletions(-) diff --git a/config/sync/field.field.node.press_release.field_address.yml b/config/sync/field.field.node.press_release.field_address.yml index 5db976f164..b53ae9a74f 100644 --- a/config/sync/field.field.node.press_release.field_address.yml +++ b/config/sync/field.field.node.press_release.field_address.yml @@ -7,6 +7,10 @@ dependencies: - node.type.press_release module: - address + - tmgmt_content +third_party_settings: + tmgmt_content: + excluded: false id: node.press_release.field_address field_name: field_address entity_type: node @@ -17,7 +21,7 @@ required: false translatable: false default_value: - - langcode: '' + langcode: en country_code: US administrative_area: '' locality: '' @@ -26,7 +30,7 @@ default_value: sorting_code: null address_line1: null address_line2: null - address_line3: '' + address_line3: null organization: null given_name: null additional_name: null @@ -34,7 +38,262 @@ default_value: default_value_callback: '' settings: available_countries: + AF: AF + AX: AX + AL: AL + DZ: DZ + AS: AS + AD: AD + AO: AO + AI: AI + AQ: AQ + AG: AG + AR: AR + AM: AM + AW: AW + AC: AC + AU: AU + AT: AT + AZ: AZ + BS: BS + BH: BH + BD: BD + BB: BB + BY: BY + BE: BE + BZ: BZ + BJ: BJ + BM: BM + BT: BT + BO: BO + BA: BA + BW: BW + BV: BV + BR: BR + IO: IO + VG: VG + BN: BN + BG: BG + BF: BF + BI: BI + KH: KH + CM: CM + CA: CA + IC: IC + CV: CV + BQ: BQ + KY: KY + CF: CF + EA: EA + TD: TD + CL: CL + CN: CN + CX: CX + CP: CP + CC: CC + CO: CO + KM: KM + CG: CG + CD: CD + CK: CK + CR: CR + CI: CI + HR: HR + CU: CU + CW: CW + CY: CY + CZ: CZ + DK: DK + DG: DG + DJ: DJ + DM: DM + DO: DO + EC: EC + EG: EG + SV: SV + GQ: GQ + ER: ER + EE: EE + SZ: SZ + ET: ET + FK: FK + FO: FO + FJ: FJ + FI: FI + FR: FR + GF: GF + PF: PF + TF: TF + GA: GA + GM: GM + GE: GE + DE: DE + GH: GH + GI: GI + GR: GR + GL: GL + GD: GD + GP: GP + GU: GU + GT: GT + GG: GG + GN: GN + GW: GW + GY: GY + HT: HT + HM: HM + HN: HN + HK: HK + HU: HU + IS: IS + IN: IN + ID: ID + IR: IR + IQ: IQ + IE: IE + IM: IM + IL: IL + IT: IT + JM: JM + JP: JP + JE: JE + JO: JO + KZ: KZ + KE: KE + KI: KI + XK: XK + KW: KW + KG: KG + LA: LA + LV: LV + LB: LB + LS: LS + LR: LR + LY: LY + LI: LI + LT: LT + LU: LU + MO: MO + MG: MG + MW: MW + MY: MY + MV: MV + ML: ML + MT: MT + MH: MH + MQ: MQ + MR: MR + MU: MU + YT: YT + MX: MX + FM: FM + MD: MD + MC: MC + MN: MN + ME: ME + MS: MS + MA: MA + MZ: MZ + MM: MM + NA: NA + NR: NR + NP: NP + NL: NL + NC: NC + NZ: NZ + NI: NI + NE: NE + NG: NG + NU: NU + NF: NF + KP: KP + MK: MK + MP: MP + 'NO': 'NO' + OM: OM + PK: PK + PW: PW + PS: PS + PA: PA + PG: PG + PY: PY + PE: PE + PH: PH + PN: PN + PL: PL + PT: PT + PR: PR + QA: QA + RE: RE + RO: RO + RU: RU + RW: RW + WS: WS + SM: SM + ST: ST + SA: SA + SN: SN + RS: RS + SC: SC + SL: SL + SG: SG + SX: SX + SK: SK + SI: SI + SB: SB + SO: SO + ZA: ZA + GS: GS + KR: KR + SS: SS + ES: ES + LK: LK + BL: BL + SH: SH + KN: KN + LC: LC + MF: MF + PM: PM + VC: VC + SD: SD + SR: SR + SJ: SJ + SE: SE + CH: CH + SY: SY + TW: TW + TJ: TJ + TZ: TZ + TH: TH + TL: TL + TG: TG + TK: TK + TO: TO + TT: TT + TA: TA + TN: TN + TR: TR + TM: TM + TC: TC + TV: TV + UM: UM + VI: VI + UG: UG + UA: UA + AE: AE + GB: GB US: US + UY: UY + UZ: UZ + VU: VU + VA: VA + VE: VE + VN: VN + WF: WF + EH: EH + YE: YE + ZM: ZM + ZW: ZW langcode_override: '' field_overrides: givenName: From bc200535e6fee312053dbf8ccedeb228370c7348 Mon Sep 17 00:00:00 2001 From: Christian Burk <766573+omahane@users.noreply.github.com> Date: Wed, 11 Dec 2024 12:55:03 -0600 Subject: [PATCH 5/8] VACMS-19227: Fixes address display and extra countries --- ...field.node.press_release.field_address.yml | 255 ------------------ .../AddPhilippinesAsStateSubscriber.php | 19 -- 2 files changed, 274 deletions(-) diff --git a/config/sync/field.field.node.press_release.field_address.yml b/config/sync/field.field.node.press_release.field_address.yml index b53ae9a74f..f35b3f1d58 100644 --- a/config/sync/field.field.node.press_release.field_address.yml +++ b/config/sync/field.field.node.press_release.field_address.yml @@ -38,262 +38,7 @@ default_value: default_value_callback: '' settings: available_countries: - AF: AF - AX: AX - AL: AL - DZ: DZ - AS: AS - AD: AD - AO: AO - AI: AI - AQ: AQ - AG: AG - AR: AR - AM: AM - AW: AW - AC: AC - AU: AU - AT: AT - AZ: AZ - BS: BS - BH: BH - BD: BD - BB: BB - BY: BY - BE: BE - BZ: BZ - BJ: BJ - BM: BM - BT: BT - BO: BO - BA: BA - BW: BW - BV: BV - BR: BR - IO: IO - VG: VG - BN: BN - BG: BG - BF: BF - BI: BI - KH: KH - CM: CM - CA: CA - IC: IC - CV: CV - BQ: BQ - KY: KY - CF: CF - EA: EA - TD: TD - CL: CL - CN: CN - CX: CX - CP: CP - CC: CC - CO: CO - KM: KM - CG: CG - CD: CD - CK: CK - CR: CR - CI: CI - HR: HR - CU: CU - CW: CW - CY: CY - CZ: CZ - DK: DK - DG: DG - DJ: DJ - DM: DM - DO: DO - EC: EC - EG: EG - SV: SV - GQ: GQ - ER: ER - EE: EE - SZ: SZ - ET: ET - FK: FK - FO: FO - FJ: FJ - FI: FI - FR: FR - GF: GF - PF: PF - TF: TF - GA: GA - GM: GM - GE: GE - DE: DE - GH: GH - GI: GI - GR: GR - GL: GL - GD: GD - GP: GP - GU: GU - GT: GT - GG: GG - GN: GN - GW: GW - GY: GY - HT: HT - HM: HM - HN: HN - HK: HK - HU: HU - IS: IS - IN: IN - ID: ID - IR: IR - IQ: IQ - IE: IE - IM: IM - IL: IL - IT: IT - JM: JM - JP: JP - JE: JE - JO: JO - KZ: KZ - KE: KE - KI: KI - XK: XK - KW: KW - KG: KG - LA: LA - LV: LV - LB: LB - LS: LS - LR: LR - LY: LY - LI: LI - LT: LT - LU: LU - MO: MO - MG: MG - MW: MW - MY: MY - MV: MV - ML: ML - MT: MT - MH: MH - MQ: MQ - MR: MR - MU: MU - YT: YT - MX: MX - FM: FM - MD: MD - MC: MC - MN: MN - ME: ME - MS: MS - MA: MA - MZ: MZ - MM: MM - NA: NA - NR: NR - NP: NP - NL: NL - NC: NC - NZ: NZ - NI: NI - NE: NE - NG: NG - NU: NU - NF: NF - KP: KP - MK: MK - MP: MP - 'NO': 'NO' - OM: OM - PK: PK - PW: PW - PS: PS - PA: PA - PG: PG - PY: PY - PE: PE - PH: PH - PN: PN - PL: PL - PT: PT - PR: PR - QA: QA - RE: RE - RO: RO - RU: RU - RW: RW - WS: WS - SM: SM - ST: ST - SA: SA - SN: SN - RS: RS - SC: SC - SL: SL - SG: SG - SX: SX - SK: SK - SI: SI - SB: SB - SO: SO - ZA: ZA - GS: GS - KR: KR - SS: SS - ES: ES - LK: LK - BL: BL - SH: SH - KN: KN - LC: LC - MF: MF - PM: PM - VC: VC - SD: SD - SR: SR - SJ: SJ - SE: SE - CH: CH - SY: SY - TW: TW - TJ: TJ - TZ: TZ - TH: TH - TL: TL - TG: TG - TK: TK - TO: TO - TT: TT - TA: TA - TN: TN - TR: TR - TM: TM - TC: TC - TV: TV - UM: UM - VI: VI - UG: UG - UA: UA - AE: AE - GB: GB US: US - UY: UY - UZ: UZ - VU: VU - VA: VA - VE: VE - VN: VN - WF: WF - EH: EH - YE: YE - ZM: ZM - ZW: ZW langcode_override: '' field_overrides: givenName: diff --git a/docroot/modules/custom/va_gov_address/src/EventSubscriber/AddPhilippinesAsStateSubscriber.php b/docroot/modules/custom/va_gov_address/src/EventSubscriber/AddPhilippinesAsStateSubscriber.php index 9356583af3..69df66d52f 100644 --- a/docroot/modules/custom/va_gov_address/src/EventSubscriber/AddPhilippinesAsStateSubscriber.php +++ b/docroot/modules/custom/va_gov_address/src/EventSubscriber/AddPhilippinesAsStateSubscriber.php @@ -2,9 +2,7 @@ namespace Drupal\va_gov_address\EventSubscriber; -use CommerceGuys\Addressing\AddressFormat\AdministrativeAreaType; use Drupal\address\Event\AddressEvents; -use Drupal\address\Event\AddressFormatEvent; use Drupal\address\Event\SubdivisionsEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -17,27 +15,10 @@ class AddPhilippinesAsStateSubscriber implements EventSubscriberInterface { * {@inheritdoc} */ public static function getSubscribedEvents() { - $events[AddressEvents::ADDRESS_FORMAT][] = ['onAddressFormat']; $events[AddressEvents::SUBDIVISIONS][] = ['onSubdivisions']; return $events; } - /** - * Alters the address format for the US. - * - * @param \Drupal\address\Event\AddressFormatEvent $event - * The address format event. - */ - public function onAddressFormat(AddressFormatEvent $event) { - $definition = $event->getDefinition(); - if ($definition['country_code'] == 'US') { - $definition['format'] = $definition['format'] . "\n%administrativeArea"; - $definition['administrative_area_type'] = AdministrativeAreaType::STATE; - $definition['subdivision_depth'] = 1; - $event->setDefinition($definition); - } - } - /** * Provides the states of the US (plus the Philippines). * From d33c186fe519edb7dfe365c470c70d3195aa00ed Mon Sep 17 00:00:00 2001 From: Daniel Sasser <221539+dsasser@users.noreply.github.com> Date: Wed, 18 Dec 2024 12:38:41 -0800 Subject: [PATCH 6/8] VACMS-19227: Adds unit test coverage for AddPhilippinesAsStateSubscriber. --- .../AddPhilippinesAsStateSubscriberTest.php | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 tests/phpunit/va_gov_address/unit/EventSubscriber/AddPhilippinesAsStateSubscriberTest.php diff --git a/tests/phpunit/va_gov_address/unit/EventSubscriber/AddPhilippinesAsStateSubscriberTest.php b/tests/phpunit/va_gov_address/unit/EventSubscriber/AddPhilippinesAsStateSubscriberTest.php new file mode 100644 index 0000000000..e9fc1b1773 --- /dev/null +++ b/tests/phpunit/va_gov_address/unit/EventSubscriber/AddPhilippinesAsStateSubscriberTest.php @@ -0,0 +1,92 @@ +subscriber = new AddPhilippinesAsStateSubscriber(); + } + + /** + * Tests the getSubscribedEvents method. + * + * @covers ::getSubscribedEvents + */ + public function testGetSubscribedEvents() { + $events = AddPhilippinesAsStateSubscriber::getSubscribedEvents(); + $this->assertArrayHasKey(AddressEvents::SUBDIVISIONS, $events); + $this->assertIsArray($events[AddressEvents::SUBDIVISIONS]); + $this->assertEquals(['onSubdivisions'], array_column($events[AddressEvents::SUBDIVISIONS], 0)); + } + + /** + * Tests the onSubdivisions method. + * + * @covers ::onSubdivisions + */ + public function testOnSubdivisions() { + // Create a mock event. + /** @var \Prophecy\Prophecy\ObjectProphecy|\Drupal\address\Event\SubdivisionsEvent $event */ + $event = $this->prophesize(SubdivisionsEvent::class); + + // Mock the getParents method to return ['US']. + $event->getParents()->willReturn(['US']); + + // Set up expected calls for getParents() and setDefinitions(). + $event->getParents()->willReturn(['US']); + $event->setDefinitions(Argument::that(function ($definitions) { + // Validate that Philippines (PH) is added as a subdivision. + return isset($definitions['subdivisions']['PH']) + && $definitions['subdivisions']['PH']['name'] === 'Philippines'; + }))->shouldBeCalled(); + + // Call the onSubdivisions method. + $this->subscriber->onSubdivisions($event->reveal()); + } + + /** + * Tests that onSubdivisions does not modify definitions for non-US parents. + * + * @covers ::onSubdivisions + */ + public function testOnSubdivisionsNonUS() { + // Create a mock event. + /** @var \Prophecy\Prophecy\ObjectProphecy|\Drupal\address\Event\SubdivisionsEvent $event */ + $event = $this->prophesize(SubdivisionsEvent::class); + + // Mock the getParents method to return a non-US parent. + $event->getParents()->willReturn(['CA']); + + // Assert that setDefinitions is never called. + $event->setDefinitions()->shouldNotBeCalled(); + + // Call the onSubdivisions method. + $this->subscriber->onSubdivisions($event->reveal()); + } + +} From 659abe4fa629be7fb531091557a5f1366fdede78 Mon Sep 17 00:00:00 2001 From: Christian Burk <766573+omahane@users.noreply.github.com> Date: Wed, 18 Dec 2024 13:53:08 -0800 Subject: [PATCH 7/8] VACMS-19227: Refactors adding PH as a state --- .../AddPhilippinesAsStateSubscriber.php | 397 +----------------- .../va_gov_address.services.yml | 1 + 2 files changed, 13 insertions(+), 385 deletions(-) diff --git a/docroot/modules/custom/va_gov_address/src/EventSubscriber/AddPhilippinesAsStateSubscriber.php b/docroot/modules/custom/va_gov_address/src/EventSubscriber/AddPhilippinesAsStateSubscriber.php index 69df66d52f..3c5be68d8e 100644 --- a/docroot/modules/custom/va_gov_address/src/EventSubscriber/AddPhilippinesAsStateSubscriber.php +++ b/docroot/modules/custom/va_gov_address/src/EventSubscriber/AddPhilippinesAsStateSubscriber.php @@ -8,6 +8,9 @@ /** * Adds a Philippines to the US States. + * + * This class follows the Centarro guidelines: + * https://docs.drupalcommerce.org/v2/developer-guide/customers/addresses/#how-do-i-add-or-modify-subdivisions-for-a-country. */ class AddPhilippinesAsStateSubscriber implements EventSubscriberInterface { @@ -26,396 +29,20 @@ public static function getSubscribedEvents() { * The subdivisions event. */ public function onSubdivisions(SubdivisionsEvent $event) { - $parents = $event->getParents(); - if ($event->getParents() != ['US']) { + if ($event->getParents() !== ['US']) { return; } - $definitions = [ - 'country_code' => $parents[0], - 'parents' => $parents, - 'subdivisions' => [ - 'AL' => [ - 'code' => 'AL', - 'name' => 'Alabama', - 'country_code' => 'US', - 'id' => 'AL', - ], - 'AK' => [ - 'code' => 'AK', - 'name' => 'Alaska', - 'country_code' => 'US', - 'id' => 'AK', - ], - 'AS' => [ - 'code' => 'AS', - 'name' => 'American Samoa', - 'country_code' => 'US', - 'id' => 'AS', - ], - 'AZ' => [ - 'code' => 'AZ', - 'name' => 'Arizona', - 'country_code' => 'US', - 'id' => 'AZ', - ], - 'AR' => [ - 'code' => 'AR', - 'name' => 'Arkansas', - 'country_code' => 'US', - 'id' => 'AR', - ], - 'AA' => [ - 'code' => 'AA', - 'name' => 'Armed Forces (AA)', - 'country_code' => 'US', - 'id' => 'AA', - ], - 'AE' => [ - 'code' => 'AE', - 'name' => 'Armed Forces (AE)', - 'country_code' => 'US', - 'id' => 'AE', - ], - 'AP' => [ - 'code' => 'AP', - 'name' => 'Armed Forces (AP)', - 'country_code' => 'US', - 'id' => 'AP', - ], - 'CA' => [ - 'code' => 'CA', - 'name' => 'California', - 'country_code' => 'US', - 'id' => 'CA', - ], - 'CO' => [ - 'code' => 'CO', - 'name' => 'Colorado', - 'country_code' => 'US', - 'id' => 'CO', - ], - 'CT' => [ - 'code' => 'CT', - 'name' => 'Connecticut', - 'country_code' => 'US', - 'id' => 'CT', - ], - 'DE' => [ - 'code' => 'DE', - 'name' => 'Delaware', - 'country_code' => 'US', - 'id' => 'DE', - ], - 'DC' => [ - 'code' => 'DC', - 'name' => 'District of Columbia', - 'country_code' => 'US', - 'id' => 'DC', - ], - 'FL' => [ - 'code' => 'FL', - 'name' => 'Florida', - 'country_code' => 'US', - 'id' => 'FL', - ], - 'GA' => [ - 'code' => 'GA', - 'name' => 'Georgia', - 'country_code' => 'US', - 'id' => 'GA', - ], - 'GU' => [ - 'code' => 'GU', - 'name' => 'Guam', - 'country_code' => 'US', - 'id' => 'GU', - ], - 'HI' => [ - 'code' => 'HI', - 'name' => 'Hawaii', - 'country_code' => 'US', - 'id' => 'HI', - ], - 'ID' => [ - 'code' => 'ID', - 'name' => 'Idaho', - 'country_code' => 'US', - 'id' => 'ID', - ], - 'IL' => [ - 'code' => 'IL', - 'name' => 'Illinois', - 'country_code' => 'US', - 'id' => 'IL', - ], - 'IN' => [ - 'code' => 'IN', - 'name' => 'Indiana', - 'country_code' => 'US', - 'id' => 'IN', - ], - 'IA' => [ - 'code' => 'IA', - 'name' => 'Iowa', - 'country_code' => 'US', - 'id' => 'IA', - ], - 'KS' => [ - 'code' => 'KS', - 'name' => 'Kansas', - 'country_code' => 'US', - 'id' => 'KS', - ], - 'KY' => [ - 'code' => 'KY', - 'name' => 'Kentucky', - 'country_code' => 'US', - 'id' => 'KY', - ], - 'LA' => [ - 'code' => 'LA', - 'name' => 'Louisiana', - 'country_code' => 'US', - 'id' => 'LA', - ], - 'ME' => [ - 'code' => 'ME', - 'name' => 'Maine', - 'country_code' => 'US', - 'id' => 'ME', - ], - 'MH' => [ - 'code' => 'MH', - 'name' => 'Marshall Islands', - 'country_code' => 'US', - 'id' => 'MH', - ], - 'MD' => [ - 'code' => 'MD', - 'name' => 'Maryland', - 'country_code' => 'US', - 'id' => 'MD', - ], - 'MA' => [ - 'code' => 'MA', - 'name' => 'Massachusetts', - 'country_code' => 'US', - 'id' => 'MA', - ], - 'MI' => [ - 'code' => 'MI', - 'name' => 'Michigan', - 'country_code' => 'US', - 'id' => 'MI', - ], - 'FM' => [ - 'code' => 'FM', - 'name' => 'Micronesia', - 'country_code' => 'US', - 'id' => 'FM', - ], - 'MN' => [ - 'code' => 'MN', - 'name' => 'Minnesota', - 'country_code' => 'US', - 'id' => 'MN', - ], - 'MS' => [ - 'code' => 'MS', - 'name' => 'Mississippi', - 'country_code' => 'US', - 'id' => 'MS', - ], - 'MO' => [ - 'code' => 'MO', - 'name' => 'Missouri', - 'country_code' => 'US', - 'id' => 'MO', - ], - 'MT' => [ - 'code' => 'MT', - 'name' => 'Montana', - 'country_code' => 'US', - 'id' => 'MT', - ], - 'NE' => [ - 'code' => 'NE', - 'name' => 'Nebraska', - 'country_code' => 'US', - 'id' => 'NE', - ], - 'NV' => [ - 'code' => 'NV', - 'name' => 'Nevada', - 'country_code' => 'US', - 'id' => 'NV', - ], - 'NH' => [ - 'code' => 'NH', - 'name' => 'New Hampshire', - 'country_code' => 'US', - 'id' => 'NH', - ], - 'NJ' => [ - 'code' => 'NJ', - 'name' => 'New Jersey', - 'country_code' => 'US', - 'id' => 'NJ', - ], - 'NM' => [ - 'code' => 'NM', - 'name' => 'New Mexico', - 'country_code' => 'US', - 'id' => 'NM', - ], - 'NY' => [ - 'code' => 'NY', - 'name' => 'New York', - 'country_code' => 'US', - 'id' => 'NY', - ], - 'NC' => [ - 'code' => 'NC', - 'name' => 'North Carolina', - 'country_code' => 'US', - 'id' => 'NC', - ], - 'ND' => [ - 'code' => 'ND', - 'name' => 'North Dakota', - 'country_code' => 'US', - 'id' => 'ND', - ], - 'MP' => [ - 'code' => 'MP', - 'name' => 'Northern Mariana Islands', - 'country_code' => 'US', - 'id' => 'MP', - ], - 'OH' => [ - 'code' => 'OH', - 'name' => 'Ohio', - 'country_code' => 'US', - 'id' => 'OH', - ], - 'OK' => [ - 'code' => 'OK', - 'name' => 'Oklahoma', - 'country_code' => 'US', - 'id' => 'OK', - ], - 'OR' => [ - 'code' => 'OR', - 'name' => 'Oregon', - 'country_code' => 'US', - 'id' => 'OR', - ], - 'PW' => [ - 'code' => 'PW', - 'name' => 'Palau', - 'country_code' => 'US', - 'id' => 'PW', - ], - 'PA' => [ - 'code' => 'PA', - 'name' => 'Pennsylvania', - 'country_code' => 'US', - 'id' => 'PA', - ], - 'PH' => [ - 'code' => 'PH', - 'name' => 'Philippines', - 'country_code' => 'US', - 'id' => 'PH', - ], + $definitions = $event->getDefinitions(); - 'PR' => [ - 'code' => 'PR', - 'name' => 'Puerto Rico', - 'country_code' => 'US', - 'id' => 'PR', - ], - 'RI' => [ - 'code' => 'RI', - 'name' => 'Rhode Island', - 'country_code' => 'US', - 'id' => 'RI', - ], - 'SC' => [ - 'code' => 'SC', - 'name' => 'South Carolina', - 'country_code' => 'US', - 'id' => 'SC', - ], - 'SD' => [ - 'code' => 'SD', - 'name' => 'South Dakota', - 'country_code' => 'US', - 'id' => 'SD', - ], - 'TN' => [ - 'code' => 'TN', - 'name' => 'Tennessee', - 'country_code' => 'US', - 'id' => 'TN', - ], - 'TX' => [ - 'code' => 'TX', - 'name' => 'Texas', - 'country_code' => 'US', - 'id' => 'TX', - ], - 'UT' => [ - 'code' => 'UT', - 'name' => 'Utah', - 'country_code' => 'US', - 'id' => 'UT', - ], - 'VT' => [ - 'code' => 'VT', - 'name' => 'Vermont', - 'country_code' => 'US', - 'id' => 'VT', - ], - 'VI' => [ - 'code' => 'VI', - 'name' => 'Virgin Islands', - 'country_code' => 'US', - 'id' => 'VI', - ], - 'VA' => [ - 'code' => 'VA', - 'name' => 'Virginia', - 'country_code' => 'US', - 'id' => 'VA', - ], - 'WA' => [ - 'code' => 'WA', - 'name' => 'Washington', - 'country_code' => 'US', - 'id' => 'WA', - ], - 'WV' => [ - 'code' => 'WV', - 'name' => 'West Virginia', - 'country_code' => 'US', - 'id' => 'WV', - ], - 'WI' => [ - 'code' => 'WI', - 'name' => 'Wisconsin', - 'country_code' => 'US', - 'id' => 'WI', - ], - 'WY' => [ - 'code' => 'WY', - 'name' => 'Wyoming', - 'country_code' => 'US', - 'id' => 'WY', - ], - ], + // Add the Philippines as a state. + $definitions['subdivisions']['PH'] = [ + 'code' => 'PH', + 'name' => 'Philippines', + 'country_code' => 'US', + 'id' => 'PH', ]; + ksort($definitions['subdivisions']); $event->setDefinitions($definitions); } diff --git a/docroot/modules/custom/va_gov_address/va_gov_address.services.yml b/docroot/modules/custom/va_gov_address/va_gov_address.services.yml index ea289c0719..6d61211083 100644 --- a/docroot/modules/custom/va_gov_address/va_gov_address.services.yml +++ b/docroot/modules/custom/va_gov_address/va_gov_address.services.yml @@ -1,5 +1,6 @@ services: va_gov_address.add_philippines_as_state_subscriber: class: Drupal\va_gov_address\EventSubscriber\AddPhilippinesAsStateSubscriber + arguments: ['@address.subdivision_repository'] tags: - { name: event_subscriber } From 51bf2a58ff1934ed8af24846622d46a9e14314fe Mon Sep 17 00:00:00 2001 From: Christian Burk <766573+omahane@users.noreply.github.com> Date: Wed, 18 Dec 2024 17:10:21 -0800 Subject: [PATCH 8/8] VACMS-19227: Refactors test to includ getDefinitions --- .../AddPhilippinesAsStateSubscriberTest.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tests/phpunit/va_gov_address/unit/EventSubscriber/AddPhilippinesAsStateSubscriberTest.php b/tests/phpunit/va_gov_address/unit/EventSubscriber/AddPhilippinesAsStateSubscriberTest.php index e9fc1b1773..e96797f47d 100644 --- a/tests/phpunit/va_gov_address/unit/EventSubscriber/AddPhilippinesAsStateSubscriberTest.php +++ b/tests/phpunit/va_gov_address/unit/EventSubscriber/AddPhilippinesAsStateSubscriberTest.php @@ -54,8 +54,18 @@ public function testOnSubdivisions() { /** @var \Prophecy\Prophecy\ObjectProphecy|\Drupal\address\Event\SubdivisionsEvent $event */ $event = $this->prophesize(SubdivisionsEvent::class); - // Mock the getParents method to return ['US']. - $event->getParents()->willReturn(['US']); + // Configure the prophecy to return specific values for getDefinitions(). + $definitions = [ + 'subdivisions' => [ + 'CA' => [ + 'code' => 'CA', + 'name' => 'California', + 'country_code' => 'US', + 'id' => 'CA', + ], + ], + ]; + $event->getDefinitions()->willReturn($definitions); // Set up expected calls for getParents() and setDefinitions(). $event->getParents()->willReturn(['US']); @@ -74,7 +84,7 @@ public function testOnSubdivisions() { * * @covers ::onSubdivisions */ - public function testOnSubdivisionsNonUS() { + public function testOnSubdivisionsNonUs() { // Create a mock event. /** @var \Prophecy\Prophecy\ObjectProphecy|\Drupal\address\Event\SubdivisionsEvent $event */ $event = $this->prophesize(SubdivisionsEvent::class);