Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Multi-Dimensional Values #69

Open
Roritchi opened this issue Dec 21, 2023 · 0 comments
Open

[BUG] Multi-Dimensional Values #69

Roritchi opened this issue Dec 21, 2023 · 0 comments

Comments

@Roritchi
Copy link

In EXT:form it is possible for Values in the $valuesWithPages, to have multiple Levels.
This would cause those Variables to not be set in the returned Value of getFormValues(). (SaveFormToDatabaseFinisher.php)

If you want to reproduce this problem, you can try using the "repeatable container" form extension for typo3.

To fix this, we have to traverse the given path, which has dots in it, through the array.
With this simple Function, this works:

protected function traversePath($conf, $path) {
        // We split each word seperated by a dot character
        $paths = explode('.', $path);
        $result = $conf;
        foreach ($paths as $path) {
            $result = $result[$path];
        }
        return $result;
    }

    /**
     * Returns the values of the submitted form
     *
     * @return []
     */
    protected function getFormValues(): array
    {
        // All values, with pages
        $valuesWithPages = $this->finisherContext->getFormValues();
        $values = [];

        // Goes trough all form-pages - and there trough all PageElements (Questions)
        foreach ($this->finisherContext->getFormRuntime()->getPages() as $page) {
            foreach ($page->getElementsRecursively() as $pageElem) {
                if ($pageElem->getType() !== 'Honeypot') {
                	if($pageElem->getType() !== 'FileUpload' && $pageElem->getType() !== 'ImageUpload'){
                        $values[$pageElem->getIdentifier()]['value'] = $this->traversePath($valuesWithPages, $pageElem->getIdentifier());
	                }else{
                		if($valuesWithPages[$pageElem->getIdentifier()]){
			                $values[$pageElem->getIdentifier()]['value'] = $valuesWithPages[$pageElem->getIdentifier()]->getOriginalResource()->getName();
		                }
	                }
                    $values[$pageElem->getIdentifier()]['conf']['label'] = $pageElem->getLabel();
                    $values[$pageElem->getIdentifier()]['conf']['inputType'] = $pageElem->getType();
                }
            }
        }
        return $values;
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant