Skip to content

Commit 7725969

Browse files
authored
Update SimpleForm.php
1 parent 01ae67a commit 7725969

File tree

1 file changed

+7
-19
lines changed

1 file changed

+7
-19
lines changed

src/LootSpace369/lsform/SimpleForm.php

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,22 @@ public function __construct(string $title, string $content, callable $onSubmit)
2121
}
2222

2323
public function addButton(string|array $text, ?string $image = null, ?callable $callback = null): self {
24-
if (is_string($text)) {
25-
$button = ["text" => $text, "callback" => $callback];
24+
$texts = is_array($text) ? $text : [$text];
25+
26+
foreach ($texts as $tex_t) {
27+
$button = ["text" => $tex_t, "callback" => $callback];
2628
if ($image !== null) {
2729
$button["image"] = [
2830
"type" => filter_var($image, FILTER_VALIDATE_URL) ? "url" : "path",
2931
"data" => $image
30-
];
32+
];
3133
}
32-
3334
$this->buttons[] = $button;
34-
return $this;
35-
}else
36-
if (is_array($text)) {
37-
foreach ($text as $tex_t) {
38-
$button = ["text" => $tex_t, "callback" => $callback];
39-
if ($image !== null) {
40-
$button["image"] = [
41-
"type" => filter_var($image, FILTER_VALIDATE_URL) ? "url" : "path",
42-
"data" => $image
43-
];
44-
}
45-
46-
$this->buttons[] = $button;
47-
}
48-
return $this;
4935
}
36+
return $this;
5037
}
5138

39+
5240
public function jsonSerialize(): array {
5341
$buttons = array_map(function($button) {
5442
$buttonData = ["text" => $button["text"]];

0 commit comments

Comments
 (0)