88use Kirby \Toolkit \Str ;
99use Kirby \Toolkit \V ;
1010use tobimori \DreamForm \DreamForm ;
11- use tobimori \DreamForm \Models \FormPage ;
1211
12+ use function intval ;
13+ use function count ;
14+
15+ /**
16+ * Action for subscribing a user to a Brevo newsletter list
17+ *
18+ * @see https://developers.brevo.com/docs/getting-started
19+ */
1320class BrevoAction extends Action
1421{
1522 public const TYPE = 'brevo ' ;
1623
1724 /**
18- * Returns the Blocks fieldset blueprint for the actions' settings
25+ * @inheritDoc
1926 */
2027 public static function blueprint (): array
2128 {
@@ -46,7 +53,7 @@ public static function blueprint(): array
4653 'list ' => [
4754 'label ' => t ('dreamform.actions.brevo.list.label ' ),
4855 'type ' => 'select ' ,
49- 'options ' => A::reduce (static ::getLists (), fn ($ prev , $ list ) => A::merge ($ prev , [
56+ 'options ' => A::reduce (static ::getLists (), fn ($ prev , $ list ) => A::merge ($ prev , [
5057 "id- {$ list ['id ' ]}" => $ list ['name ' ]
5158 ]), []),
5259 'required ' => true ,
@@ -63,7 +70,7 @@ public static function blueprint(): array
6370 'type ' => count (static ::getTemplates ()) > 0 ? 'select ' : 'info ' ,
6471 'width ' => '1/2 ' ,
6572 'required ' => count (static ::getTemplates ()) > 0 ,
66- 'options ' => A::reduce (static ::getTemplates (), fn ($ prev , $ template ) => A::merge ($ prev , [
73+ 'options ' => A::reduce (static ::getTemplates (), fn ($ prev , $ template ) => A::merge ($ prev , [
6774 "id- {$ template ['id ' ]}" => $ template ['name ' ]
6875 ]), []),
6976 'help ' => count (static ::getTemplates ()) > 0
@@ -166,7 +173,7 @@ public function run(): void
166173 }
167174
168175 $ listId = intval (Str::replace ($ list , 'id- ' , '' ));
169- $ listEntry = A::find (static ::getLists (), fn ($ entry ) => $ entry ['id ' ] === $ listId );
176+ $ listEntry = A::find (static ::getLists (), fn ($ entry ) => $ entry ['id ' ] === $ listId );
170177
171178 $ this ->log (
172179 [
@@ -188,7 +195,7 @@ protected static function getLists(): array
188195 {
189196 $ response = static ::cache (
190197 'lists ' ,
191- fn () => static ::request ('GET ' , '/contacts/lists ' )?->json()
198+ fn () => static ::request ('GET ' , '/contacts/lists ' )?->json()
192199 );
193200
194201 return $ response ['lists ' ] ?? [];
@@ -201,7 +208,7 @@ protected static function getTemplates(): array
201208 {
202209 $ response = static ::cache (
203210 'templates ' ,
204- fn () => static ::request ('GET ' , '/smtp/templates?limit=1000 ' )?->json()
211+ fn () => static ::request ('GET ' , '/smtp/templates?limit=1000 ' )?->json()
205212 );
206213
207214 return $ response ['templates ' ] ?? [];
@@ -215,7 +222,7 @@ protected static function getAttributeFields(): array
215222 {
216223 $ response = static ::cache (
217224 'attributes ' ,
218- fn () => static ::request ('GET ' , '/contacts/attributes ' )?->json()
225+ fn () => static ::request ('GET ' , '/contacts/attributes ' )?->json()
219226 );
220227
221228 $ attributes = $ response ['attributes ' ] ?? [];
@@ -262,14 +269,14 @@ public static function request(string $method, string $url, array $data = []): R
262269 {
263270 if ($ method !== 'GET ' ) {
264271 $ params = [
265- 'data ' => Json::encode (A::filter ($ data , fn ($ value ) => $ value !== null )),
272+ 'data ' => Json::encode (A::filter ($ data , fn ($ value ) => $ value !== null )),
266273 'headers ' => [
267274 'Content-Type ' => 'application/json ' ,
268275 ]
269276 ];
270277 }
271278
272- return Remote::$ method (' https://api.brevo.com/v3/ ' . $ url , A::merge (
279+ return Remote::$ method (" https://api.brevo.com/v3/ { $ url}" , A::merge (
273280 $ params ?? [],
274281 [
275282 'headers ' => [
@@ -289,15 +296,15 @@ public static function isAvailable(): bool
289296 }
290297
291298 /**
292- * Returns the actions' blueprint group
299+ * @inheritDoc
293300 */
294301 public static function group (): string
295302 {
296303 return 'newsletter ' ;
297304 }
298305
299306 /**
300- * Returns the base log settings for the action
307+ * @inheritDoc
301308 */
302309 protected function logSettings (): array |bool
303310 {
0 commit comments