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 #1

Updated by Bill Dagou over 5 years ago

A tricky thing is, when I use

class Condition extends AbstractDomainObject {
    ......
}

the PropertyMapper works as expected.

Actions #2

Updated by Bill Dagou over 5 years ago

After some more researching, it's caused by the differencs between \TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter::getTypeOfChildProperty() and \TYPO3\CMS\Extbase\Property\TypeConverter\ObjectConverter::getTypeOfChildProperty().

Actions #3

Updated by Wolfgang Klinger over 5 years ago

I can't see the bug here … when you create an Extbase model, you extend 'AbstractEntity' … why wouldn't you do that? That's just something you left out and expect it to work nonetheless(?)

Actions #4

Updated by Bill Dagou over 5 years ago

Oh sorry, as I don't need the Condition to be persisted in the database. So, do you mean all the models in Extbase should be extended from AbstractDomainObject? If so, what's \TYPO3\CMS\Extbase\Property\TypeConverter\ObjectConverter for?

BTW, I could come up a test ext to duplicate the problem if you neeed.

Actions #5

Updated by Bill Dagou over 5 years ago

Please try the attached extension, and create a few test objects before starting test.

Actions #6

Updated by Wolfgang Klinger over 5 years ago

  • Status changed from New to Needs Feedback

So, do you mean all the models in Extbase should be extended from AbstractDomainObject

Yes, of course.
If you don't need persistence, just don't use a Repository.
Nobody forces you to create a database table just because you extend a specific class here.

Actions #7

Updated by Bill Dagou over 5 years ago

OK. Sorry for the interrupt.

Actions #8

Updated by Riccardo De Contardi about 5 years ago

  • Status changed from Needs Feedback to Closed

Thanks for your reply

I close this for now. If you think that this is the wrong decision, please reopen it or ping me.

Actions

Also available in: Atom PDF