Issue Bug Closed

#86931PropertyMapper doesn't map ObjectStorage correctly

Bill Dagou 11/15/18, 11:04 updated 02/24/19, 11:53

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

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.