From 7725969f0869eb62f1df7979d1238bb66c537a82 Mon Sep 17 00:00:00 2001 From: LSpace Date: Sat, 20 Jul 2024 21:24:52 +0700 Subject: [PATCH] Update SimpleForm.php --- src/LootSpace369/lsform/SimpleForm.php | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/src/LootSpace369/lsform/SimpleForm.php b/src/LootSpace369/lsform/SimpleForm.php index f25c6b8..a8063e7 100644 --- a/src/LootSpace369/lsform/SimpleForm.php +++ b/src/LootSpace369/lsform/SimpleForm.php @@ -21,34 +21,22 @@ public function __construct(string $title, string $content, callable $onSubmit) } public function addButton(string|array $text, ?string $image = null, ?callable $callback = null): self { - if (is_string($text)) { - $button = ["text" => $text, "callback" => $callback]; + $texts = is_array($text) ? $text : [$text]; + + foreach ($texts as $tex_t) { + $button = ["text" => $tex_t, "callback" => $callback]; if ($image !== null) { $button["image"] = [ "type" => filter_var($image, FILTER_VALIDATE_URL) ? "url" : "path", "data" => $image - ]; + ]; } - $this->buttons[] = $button; - return $this; - }else - if (is_array($text)) { - foreach ($text as $tex_t) { - $button = ["text" => $tex_t, "callback" => $callback]; - if ($image !== null) { - $button["image"] = [ - "type" => filter_var($image, FILTER_VALIDATE_URL) ? "url" : "path", - "data" => $image - ]; - } - - $this->buttons[] = $button; - } - return $this; } + return $this; } + public function jsonSerialize(): array { $buttons = array_map(function($button) { $buttonData = ["text" => $button["text"]];