diff --git a/src/AdminPanel/Form/ArrayInput.php b/src/AdminPanel/Form/ArrayInput.php new file mode 100644 index 0000000..a774e29 --- /dev/null +++ b/src/AdminPanel/Form/ArrayInput.php @@ -0,0 +1,71 @@ +options = array( + 'elements' => array() + ); + $this->setOption("type", "text"); + } + + public function getOptionsList(): array + { + return array_merge( + parent::getOptionsList(), + array( + "array_type", + "item", + "script" + ) + ); + } + + public function getAttributesList(): array + { + return array( + 'name', + 'id', + ); + } + + public function setOption(string $name, $value) + { + if ($name === "array_type") { + $clas = $value; + $input = new $clas(); + $input->setOption("id", $this->attributes["name"] . "-__unique__"); + $input->setOption("name", $this->attributes["name"] . "[__unique__]"); + $this->options["data-element"] = $input; + } elseif ($name === "item") { + foreach ($value as $vname => $vvalue) { + $this->options["data-element"]->setOption($vname, $vvalue); + } + } + parent::setOption($name, $value); + } + + public function render(): string + { + if (array_key_exists("array_type", $this->options) && + array_key_exists("value", $this->options) + ) { + $clas = $this->options["array_type"]; + if (isset($this->options["value"])) { + foreach ($this->options["value"] as $key => $value) { + $input = new $clas(); + $input->setOption("id", $this->attributes["name"] . "-" . $key); + $input->setOption("name", $this->attributes["name"] . "[" . $key . "]"); + $input->setOption("value", $value); + $this->options["elements"][] = $input; + } + } + } + $this->attributes["data-element"] = "" . $this->options["data-element"]->render() . ""; + return parent::render(); + } +} diff --git a/src/AdminPanel/Form/DatalistInput.php b/src/AdminPanel/Form/DatalistInput.php new file mode 100644 index 0000000..44cda12 --- /dev/null +++ b/src/AdminPanel/Form/DatalistInput.php @@ -0,0 +1,24 @@ +attributes["list"] = $name . "_list"; + } + parent::setOption($name, $value); + } +} diff --git a/src/AdminPanel/Form/NumberInput.php b/src/AdminPanel/Form/NumberInput.php new file mode 100644 index 0000000..fff3245 --- /dev/null +++ b/src/AdminPanel/Form/NumberInput.php @@ -0,0 +1,17 @@ + + {{item.render()|raw}} + + {% endfor %} +{% endblock %} + +{% block after %} + +{% endblock %} diff --git a/src/AdminPanel/Twig/form/datalist.twig b/src/AdminPanel/Twig/form/datalist.twig new file mode 100644 index 0000000..09d2c8f --- /dev/null +++ b/src/AdminPanel/Twig/form/datalist.twig @@ -0,0 +1,9 @@ +{% extends "@AdminPanel/form/_default.twig" %} + +{% block after %} + + {% for element in options.list %} + + {% endfor %} + +{% endblock %} diff --git a/src/AdminPanel/Twig/form/number.twig b/src/AdminPanel/Twig/form/number.twig new file mode 100644 index 0000000..1586fdb --- /dev/null +++ b/src/AdminPanel/Twig/form/number.twig @@ -0,0 +1 @@ +{% extends "@AdminPanel/form/_default.twig" %}