Skip to content

[BUG] Multi-Dimensional Values #69

@davidprojekt

Description

@davidprojekt

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;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions