- Added UiSelect widget - Fixed UiForm widget - Fixed UiInput widget - Added mocks of UiMessage and UiPopup. Not even a WIP at this stage.
60 lines
1.5 KiB
PHP
60 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Picea\Ui\Form;
|
|
|
|
use Picea\Ui\Common\UiElement;
|
|
use Picea\Extension\Extension;
|
|
use Picea\Extension\ExtensionTrait;
|
|
|
|
class UiForm extends UiElement implements Extension {
|
|
use ExtensionTrait;
|
|
|
|
public string $defaultMethod = "get";
|
|
|
|
public array $token = [ "ui.form", "ui.endform", "ui.form.get", "ui.form.post", "ui.form.patch", "ui.form.delete", "ui.form.put" ];
|
|
|
|
public string $tag = "form";
|
|
|
|
public array $attributes = [
|
|
'class' => 'ui-form',
|
|
];
|
|
|
|
public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) : string
|
|
{
|
|
switch($token) {
|
|
case 'ui.endform':
|
|
return "</form>";
|
|
|
|
case "ui.form.get":
|
|
$method = "get";
|
|
break;
|
|
|
|
case "ui.form.patch":
|
|
$method = "patch";
|
|
break;
|
|
|
|
case "ui.form.delete":
|
|
$method = "delete";
|
|
break;
|
|
|
|
case "ui.form.put":
|
|
$method = "put";
|
|
break;
|
|
|
|
case "ui.form.post":
|
|
$method = "post";
|
|
break;
|
|
}
|
|
|
|
$method ??= $this->defaultMethod;
|
|
return "<?php echo ( new \\" . static::class . "() )->buildHtml('$method', $arguments) ?>";
|
|
}
|
|
|
|
public function buildHtml(string $method, string $action, array $attributes = []) : string
|
|
{
|
|
$this->option('tag-type', 'single');
|
|
$this->attributes([ 'action' => $action ] + $attributes);
|
|
return $this->render() . PHP_EOL;
|
|
}
|
|
}
|