- First commit, work done on form input
This commit is contained in:
commit
a0bf505377
24 files changed
+934
No files matched your search
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace Picea\Ui\Form;
|
||||
|
||||
use Picea\Ui\Common\UiElement;
|
||||
use Picea\Extension\Extension;
|
||||
|
||||
class UiForm extends UiElement implements Extension {
|
||||
|
||||
public string $defaultMethod = "get";
|
||||
|
||||
public string $token = "ui.form";
|
||||
|
||||
public string $tag = "form";
|
||||
|
||||
public array $attributes = [
|
||||
'class' => 'ui-form',
|
||||
];
|
||||
|
||||
public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) : string
|
||||
{
|
||||
list($action, $options) = array_pad(explode(',', $arguments), 2, null);
|
||||
|
||||
switch($token) {
|
||||
case "ui.form.get":
|
||||
$this->attributes['method'] = "get";
|
||||
break;
|
||||
|
||||
case "ui.form.post":
|
||||
$this->attributes['method'] = "post";
|
||||
break;
|
||||
|
||||
default:
|
||||
case $this->token:
|
||||
$this->attributes['method'] = $this->defaultMethod;
|
||||
break;
|
||||
}
|
||||
|
||||
$this->attributes['action'] = $action;
|
||||
$this->attributes($this->parseAttributes($options));
|
||||
return $this->render();
|
||||
}
|
||||
|
||||
protected function parseAttributes(string $options) : array
|
||||
{
|
||||
if ( $options ?? false ) {
|
||||
$attributes = eval($options);
|
||||
|
||||
if ( ! is_array($attributes) ) {
|
||||
throw new InvalidArgumentException("Given options `$options` is not a valid attributes array.");
|
||||
}
|
||||
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user