| 1 |
<?php |
| 2 |
|
| 3 |
namespace IvyForms\Services\GoogleSheets\Hooks; |
| 4 |
|
| 5 |
/** |
| 6 |
* Injects Google Sheets integration data into the global settings API response. |
| 7 |
*/ |
| 8 |
class SettingsHook |
| 9 |
{ |
| 10 |
/** |
| 11 |
* @param array<string, mixed> $organizedSettings |
| 12 |
* @param array<string, mixed> $allSettings |
| 13 |
* @return array<string, mixed> |
| 14 |
*/ |
| 15 |
public function addIntegrationData(array $organizedSettings, array $allSettings): array |
| 16 |
{ |
| 17 |
$googleSheetsSettings = $allSettings['integrations']['google_sheets'] ?? null; |
| 18 |
|
| 19 |
if (!is_array($googleSheetsSettings)) { |
| 20 |
$organizedSettings['integrations']['google_sheets'] = [ |
| 21 |
'enabled' => false, |
| 22 |
'connected' => false, |
| 23 |
]; |
| 24 |
|
| 25 |
return $organizedSettings; |
| 26 |
} |
| 27 |
|
| 28 |
$organizedSettings['integrations']['google_sheets'] = [ |
| 29 |
'enabled' => !empty($googleSheetsSettings['enabled']), |
| 30 |
'connected' => !empty($googleSheetsSettings['refreshToken']), |
| 31 |
]; |
| 32 |
|
| 33 |
return $organizedSettings; |
| 34 |
} |
| 35 |
} |
| 36 |
|