Skip to content

Commit

Permalink
Update SimpleForm.php
Browse files Browse the repository at this point in the history
  • Loading branch information
Vasync authored Jul 20, 2024
1 parent 01ae67a commit 7725969
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions src/LootSpace369/lsform/SimpleForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"]];
Expand Down

0 comments on commit 7725969

Please sign in to comment.