@@ -48,19 +48,15 @@ public static function displayName(): string
4848 public function __construct ($ config = [])
4949 {
5050 // Config normalization
51- if (array_key_exists ('webhook ' , $ config )) {
52- $ config ['url ' ] = ArrayHelper::remove ($ config , 'webhook ' );
53- }
51+ $ config = $ this ->_normalizeConfig ($ config );
5452
5553 parent ::__construct ($ config );
5654 }
5755
5856 public function setAttributes ($ values , $ safeOnly = true ): void
5957 {
6058 // Handle legacy webhook from the form settings, which won't be via `__construct`
61- if (array_key_exists ('webhook ' , $ values )) {
62- $ values ['url ' ] = ArrayHelper::remove ($ values , 'webhook ' );
63- }
59+ $ values = $ this ->_normalizeConfig ($ values );
6460
6561 parent ::setAttributes ($ values , $ safeOnly );
6662 }
@@ -208,5 +204,23 @@ protected function defineClient(): Client
208204 }
209205
210206 return Craft::createGuzzleClient ($ config );
211- }
207+ }
208+
209+
210+ // Private Methods
211+ // =========================================================================
212+
213+ private function _normalizeConfig (array $ config ): array
214+ {
215+ // Remove the legacy `webhook` key, and use the `url` key instead
216+ $ legacyUrl = ArrayHelper::remove ($ config , 'webhook ' );
217+ $ url = $ config ['url ' ] ?? null ;
218+
219+ if ($ legacyUrl && !$ url ) {
220+ $ config ['url ' ] = $ legacyUrl ;
221+ }
222+
223+ return $ config ;
224+ }
225+
212226}
0 commit comments