Project

General

Profile

Actions

Bug #86931

closed

PropertyMapper doesn't map ObjectStorage correctly

Added by Bill Dagou over 5 years ago. Updated about 5 years ago.

Status:
Closed
Priority:
Must have
Assignee:
-
Category:
-
Target version:
-
Start date:
2018-11-15
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
8
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

Some code snippet as follow:

Model

<?php
class Condition {
    /**
     * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<Dagou\Project\Domain\Model\Project>
     */
    protected $project;

    public function __construct() {
        $this->project = new ObjectStorage();
    }

    /**
     * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $project
     *
     * @return \Dagou\Statistics\Domain\Model\Condition
     */
    public function setProject(ObjectStorage $project) {
        $this->project = $project;

        return $this;
    }

    /**
     * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
     */
    public function getProject() {
        return $this->project;
    }
}

Controller

<?php
class StatisticsController extends ActionController {
    /**
     * @var ProjectRepository
     * @inject
     */
    protected $projectRepository;

    /**
     * @param Condition $condition
     */
    protected function indexAction(Condition $condition = NULL) {
        $this->view->assignMultiple(
            [
                'condition' => $condition,
                'projects' => $this->projectRepository->findAll(),
            ]
        );
    }

    /**
     * @param Condition $condition
     */
    protected function processAction(Condition $condition) {
        ......
    }
}

Index.html

<html xmlns="http://www.w3.org/1999/xhtml" 
        lang="en" 
        xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" 
        data-namespace-typo3-fluid="true">
<f:form action="process" object="{condition}" objectName="condition">
    <div class="form-group row">
        <label class="col-sm-3 col-lg-2 col-form-label" for="project">Projects</label>
        <div class="col-sm-4 col-md-3 col-lg-2">
            <f:form.select id="project" 
                    class="form-control" 
                    multiple="true" 
                    options="{projects}" 
                    optionValueField="uid" 
                    optionLabelField="name" 
                    prependOptionLabel="- Select Project -" 
                    property="project" />
        </div>
    </div>
    <div class="form-group row">
        <div class="col-sm-9 col-lg-10 offset-sm-3 offset-lg-2">
            <button class="btn btn-primary" type="submit">Submit</button>
        </div>
    </div>
</f:form>
</html>

When I submit the form, I will get the error, which says

#1297759968: Exception while property mapping at property path "project.0": The target type was no string, but of type "NULL" 

After some debug, I think it's because the PropertyMapper doesn't map the $project correctly, which should be TYPO3\CMS\Extbase\Persistence\ObjectStorage<Dagou\Project\Domain\Model\Project> instead of TYPO3\CMS\Extbase\Persistence\ObjectStorage


Files

test.zip (8.32 KB) test.zip Bill Dagou, 2018-11-20 06:47
Actions

Also available in: Atom PDF