54 lines
1.4 KiB
PHP
54 lines
1.4 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" ];
|
|
|
|
public string $tag = "form";
|
|
|
|
public array $attributes = [
|
|
'class' => 'ui-form',
|
|
];
|
|
|
|
public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) : string
|
|
{
|
|
if ( $token === 'ui.endform' ) {
|
|
return "</form>";
|
|
}
|
|
|
|
list($action, $options) = array_pad(explode(',', $arguments), 2, null);
|
|
|
|
$action = $this->trim($action);
|
|
|
|
switch($token) {
|
|
case "ui.form.get":
|
|
$this->attributes['method'] = "get";
|
|
break;
|
|
|
|
case "ui.form.post":
|
|
$this->attributes['method'] = "post";
|
|
$this->attributes['enctype'] = "multipart/form-data";
|
|
break;
|
|
|
|
default:
|
|
case $this->token:
|
|
$this->attributes['method'] = $this->defaultMethod;
|
|
break;
|
|
}
|
|
|
|
$this->option('tag-type', 'single');
|
|
$this->attributes['action'] = $this->trim($action);
|
|
$this->attributes($this->parseOptions($options));
|
|
return $this->render();
|
|
}
|
|
}
|