summaryrefslogtreecommitdiff
path: root/src/Builder.php
diff options
context:
space:
mode:
authorDaniel Weipert <code@drogueronin.de>2022-03-06 11:45:31 +0100
committerDaniel Weipert <code@drogueronin.de>2022-03-06 11:45:31 +0100
commit1334236bb6059b2302a760196ce7885df379e984 (patch)
treef86e883e6ae9510454307f38be3ffd20aefa6c4c /src/Builder.php
parentad83d1dafac62bb28fda004f86129319a5c3e2ca (diff)
toml to yaml
Diffstat (limited to 'src/Builder.php')
-rw-r--r--src/Builder.php35
1 files changed, 22 insertions, 13 deletions
diff --git a/src/Builder.php b/src/Builder.php
index 308fa82..1172fc8 100644
--- a/src/Builder.php
+++ b/src/Builder.php
@@ -2,7 +2,7 @@
namespace FlatFileForms;
-use Yosymfony\Toml\Toml;
+use Symfony\Component\Yaml\Yaml;
class Builder
{
@@ -13,27 +13,33 @@ class Builder
public function buildFields(mixed $page = null)
{
- $parsed = Toml::parseFile($this->formPath . '/fields/_fields.toml');
+ /**@var HookManager $hooks*/
+ global $hooks;
+
+ /**@var Form $form*/
+ global $form;
+
+ $parsed = Yaml::parseFile($this->formPath . '/fields/_fields.yaml');
$fields = [];
// if a page is requested
if ($page) {
- if (! isset($parsed['page'])) {
+ if (! isset($parsed['pages'])) {
throw new \Exception('Form has no pages');
}
- if (! isset($parsed['page'][$page])) {
+ if (! isset($parsed['pages'][$page])) {
throw new \Exception('Form has no page ' . $page);
}
- $fields = $this->buildSinglePageFields($parsed['page'][$page]);
+ $fields = $this->buildSinglePageFields($parsed['pages'][$page]);
}
// else get all fields
else {
// if form is paged
- if (isset($parsed['page'])) {
- $pages = $parsed['page'];
+ if (isset($parsed['pages'])) {
+ $pages = $parsed['pages'];
foreach ($pages as $pageKey => $pageFields) {
$fields[$pageKey] = $this->buildSinglePageFields($pageFields);
}
@@ -41,34 +47,37 @@ class Builder
// if form is not paged
else {
- foreach ($parsed['field'] as $key => $field) {
+ foreach ($parsed as $key => $field) {
$fields[$key] = $this->buildSingleField($key, $field);
}
}
}
+ $fields = $hooks->applyFilter("builder:{$form->name}:fields", $fields);
+ $fields = $hooks->applyFilter('builder:fields', $fields);
+
return $fields;
}
- public function buildSinglePageFields(array $pageFields): array
+ private function buildSinglePageFields(array $pageFields): array
{
$fields = [];
if (! empty($pageFields['file'])) {
- $pageFields = array_replace_recursive($pageFields, Toml::parseFile($this->formPath . '/fields/' . $pageFields['file']));
+ $pageFields = array_replace_recursive($pageFields, Yaml::parseFile($this->formPath . '/fields/' . $pageFields['file']));
}
- foreach ($pageFields['field'] as $key => $field) {
+ foreach ($pageFields['fields'] as $key => $field) {
$fields[$key] = $this->buildSingleField($key, $field);
}
return $fields;
}
- public function buildSingleField(string $key, array $field): array
+ private function buildSingleField(string $key, array $field): array
{
if (! empty($field['file'])) {
- $field = array_replace_recursive($field, Toml::parseFile($this->formPath . '/fields/' . $field['file']));
+ $field = array_replace_recursive($field, Yaml::parseFile($this->formPath . '/fields/' . $field['file']));
}
if (empty($field['name'])) {