| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace IvyForms\Services\Template; |
| 4 | 4 | |
| 5 | +use IvyForms\Common\Constants\SupportedCurrencyCodes; | |
| 5 | 6 | use IvyForms\Common\Exceptions\InvalidArgumentException; |
| 6 | 7 | use IvyForms\Services\Translations\BackendStrings; |
| 7 | 8 | |
| 8 | 9 | /** |
| @@ -41,8 +42,25 @@ | ||
| 41 | 42 | return self::DEFAULT_INTEGRATION_SETTINGS; |
| 42 | 43 | } |
| 43 | 44 | |
| 44 | 45 | /** |
| 46 | + * Default payment settings for new forms. | |
| 47 | + * | |
| 48 | + * @var array{currency:string} | |
| 49 | + */ | |
| 50 | + public const DEFAULT_PAYMENT_SETTINGS = [ | |
| 51 | + 'currency' => SupportedCurrencyCodes::DEFAULT_CODE, | |
| 52 | + ]; | |
| 53 | + | |
| 54 | + /** | |
| 55 | + * @return array{currency:string} | |
| 56 | + */ | |
| 57 | + public static function getDefaultPaymentSettings(): array | |
| 58 | + { | |
| 59 | + return self::DEFAULT_PAYMENT_SETTINGS; | |
| 60 | + } | |
| 61 | + | |
| 62 | + /** | |
| 45 | 63 | * Get default form style settings from bundled JSON (`backend/resources/defaultFormStyles.json`). |
| 46 | 64 | * |
| 47 | 65 | * @return array<string, mixed> |
| 48 | 66 | * @throws InvalidArgumentException |
| @@ -84,9 +102,9 @@ | ||
| 84 | 102 | if (!is_array($decoded)) { |
| 85 | 103 | throw new InvalidArgumentException($exceptionStrings['default_styles_json_invalid_structure']); |
| 86 | 104 | } |
| 87 | 105 | |
| 88 | - self::$cachedFormStyles = $decoded; | |
| 106 | + self::$cachedFormStyles = self::filterDefaultFormStyles($decoded); | |
| 89 | 107 | |
| 90 | 108 | return self::$cachedFormStyles; |
| 91 | 109 | } |
| 92 | 110 | |
| @@ -99,9 +117,9 @@ | ||
| 99 | 117 | { |
| 100 | 118 | try { |
| 101 | 119 | return self::getDefaultFormStyles(); |
| 102 | 120 | } catch (InvalidArgumentException $e) { |
| 103 | - return self::getMinimalFormStyleSettingsFallback(); | |
| 121 | + return self::filterDefaultFormStyles(self::getMinimalFormStyleSettingsFallback()); | |
| 104 | 122 | } |
| 105 | 123 | } |
| 106 | 124 | |
| 107 | 125 | /** |
| @@ -119,8 +137,31 @@ | ||
| 119 | 137 | 'additionalCssClasses' => '', |
| 120 | 138 | 'quickMode' => [], |
| 121 | 139 | 'advancedMode' => [], |
| 122 | 140 | ]; |
| 141 | + } | |
| 142 | + | |
| 143 | + /** | |
| 144 | + * Allow Pro (and other extensions) to merge plan-specific default style sections. | |
| 145 | + * | |
| 146 | + * @param array<string, mixed> $defaults | |
| 147 | + * @return array<string, mixed> | |
| 148 | + */ | |
| 149 | + private static function filterDefaultFormStyles(array $defaults): array | |
| 150 | + { | |
| 151 | + /** @var mixed $filtered */ | |
| 152 | + $filtered = apply_filters('ivyforms/style/filter/default_form_styles', $defaults); | |
| 153 | + | |
| 154 | + if (!is_array($filtered)) { | |
| 155 | + error_log( | |
| 156 | + 'IvyForms: ivyforms/style/filter/default_form_styles filter must return an array; ' | |
| 157 | + . 'using bundled defaults.' | |
| 158 | + ); | |
| 159 | + | |
| 160 | + return $defaults; | |
| 161 | + } | |
| 162 | + | |
| 163 | + return $filtered; | |
| 123 | 164 | } |
| 124 | 165 | |
| 125 | 166 | /** |
| 126 | 167 | * Absolute path to the bundled default form styles JSON. |