From 43ec8517cbc42093ad1f17063495f79e6eddf1cf Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Wed, 5 Jan 2022 17:05:10 +0100 Subject: Build pages with file fields --- src/App.php | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/App.php b/src/App.php index 107113a..a155017 100644 --- a/src/App.php +++ b/src/App.php @@ -171,9 +171,7 @@ class App throw new \Exception('Form has no page ' . $page); } - foreach ($parsed['page'][$page]['field'] as $key => $field) { - $fields[$key] = $this->buildSingleField($formPath, $key, $field); - } + $fields = $this->buildSinglePageFields($parsed['page'][$page], $formPath); } // else get all fields @@ -182,9 +180,7 @@ class App if (isset($parsed['page'])) { $pages = $parsed['page']; foreach ($pages as $pageKey => $pageFields) { - foreach ($pageFields['field'] as $key => $field) { - $fields[$pageKey][$key] = $this->buildSingleField($formPath, $key, $field); - } + $fields[$pageKey] = $this->buildSinglePageFields($pageFields, $formPath); } } @@ -199,6 +195,25 @@ class App return $fields; } + /** + * @param array $pageFields + * @param string $formPath + */ + public function buildSinglePageFields($pageFields, $formPath) + { + $fields = []; + + if (! empty($pageFields['file'])) { + $pageFields = array_replace_recursive($pageFields, Toml::parseFile($formPath . '/fields/' . $pageFields['file'])); + } + + foreach ($pageFields['field'] as $key => $field) { + $fields[$key] = $this->buildSingleField($formPath, $key, $field); + } + + return $fields; + } + /** * @param string $formPath * @param string $key -- cgit v1.2.3