Bug #86931
closedPropertyMapper doesn't map ObjectStorage correctly
0%
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
Updated by Bill Dagou about 6 years ago
A tricky thing is, when I use
class Condition extends AbstractDomainObject {
......
}
the PropertyMapper works as expected.
Updated by Bill Dagou about 6 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()
.
Updated by Wolfgang Klinger about 6 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(?)
Updated by Bill Dagou about 6 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.
Updated by Bill Dagou about 6 years ago
Please try the attached extension, and create a few test objects before starting test.
Updated by Wolfgang Klinger almost 6 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.
Updated by Riccardo De Contardi over 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.