Skip to content

Advanced

VennV edited this page Jul 29, 2024 · 6 revisions

Let's say you want to get strings from config or external files into the Form's headers and contents?

GetString

...
use Override;
use venndev\vformoopapi\results\VResultString;

final class GetString extends VResultString
{

    public function __construct(string $input)
    {
        parent::__construct($input);
    }

    #[Override] public function getResult(): string
    {
        return YourPlugin::getInstance()->getConfig()->getNested($this->getInput());
    }

}

YourForm

use pocketmine\player\Player;
use venndev\vform\results\GetString;
use venndev\vformoopapi\attributes\normal\VButton;
use venndev\vformoopapi\attributes\VForm;
use venndev\vformoopapi\Form;
use venndev\vformoopapi\utils\TypeForm;

#[VForm(
    title: "My Form",
    type: TypeForm::NORMAL_FORM,
    content: ""
)]
final class YourForm extends Form
{

    public function __construct(Player $player)
    {
        parent::__construct($player);
        $this->setContent("Welcome to the server!");
    }

    #[VButton(
        text: new GetString("messages.hello_world"), // Process text button with class GetString
        image: "...",
        label: "Click me!"
    )]
    public function testButton(Player $player, mixed $data): void
    {
        $player->sendMessage("You clicked the test button!");
    }

    protected function onClose(Player $player): void
    {
        $player->sendMessage("You have closed the form");
    }

    // This method is called when the form is submitted
    protected function onCompletion(Player $player, mixed $data): void
    {
        // TODO: Implement onCompletion() method.
    }

}
Clone this wiki locally