You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I noticed, that my form was not validating correctly. After some digging in code, I found, that although inputSpec is properly set in ElementAnnotationsListener::handleComposedObjectAnnotation, it gets ignored in AnnotationBuilder::configureElement
So here is what I found was causing it, and how I fixed it (although I am not sure, if that is correct):
AnnotationBulder.php:
protectedfunctionconfigureElement($annotations, $reflection, $formSpec, $filterSpec)
{
// If the element is marked as exclude, return earlyif ($this->checkForExclude($annotations)) {
return;
}
$events = $this->getEventManager();
$name = $this->discoverName($annotations, $reflection);
$elementSpec = newArrayObject([
'flags' => [],
'spec' => [
'name' => $name
],
]);
$inputSpec = newArrayObject([
'name' => $name,
]);
$params = [
'name' => $name,
'elementSpec' => $elementSpec,
'inputSpec' => $inputSpec, // Before the fix, this would not change its vallue'formSpec' => $formSpec,
'filterSpec' => $filterSpec,
];
foreach ($annotationsas$annotation) {
$params['annotation'] = $annotation;
// -> This causes ElementAnnotationsListener::handleComposedObjectAnnotation to configure the element$events->trigger(__FUNCTION__, $this, $params);
}
// Rest of the code is omitted (not relevant)
}
ElementAnnotationsListener.php:
publicfunctionhandleComposedObjectAnnotation($e)
{
$annotation = $e->getParam('annotation');
if (!$annotationinstanceof ComposedObject) {
return;
}
$class = $annotation->getComposedObject();
$annotationManager = $e->getTarget();
$specification = $annotationManager->getFormSpecification($class);
$name = $e->getParam('name');
$elementSpec = $e->getParam('elementSpec');
if ($annotation->isCollection()) {
// Omitted, not relevant
} else {
// Compose input filter into parent input filter$inputFilter = $specification['input_filter'];
if (!isset($inputFilter['type'])) {
$inputFilter['type'] = 'Zend\InputFilter\InputFilter';
}
// So here is what causes the problem:// For some reason setting inputSpec like this causes it to be ignored in AnnotationBuilder::configureElement// $e->setParam('inputSpec', $inputFilter);// This seems to work, now the composed object receives the correct inputSpec/** @var ArrayObject $inputSpec */$inputSpec = $e->getParam('inputSpec');
$inputSpec->exchangeArray($inputFilter);
unset($specification['input_filter']);
// Rest of the code is omitted, not relevant
}
}
I don't believe that this is expected behavior, because every other aspect of the element configuration can be set in ElementAnnotationsListener::handleComposedObjectAnnotation.
This is messing up my code too. I tried the fix above and it works. I'm planning to handle the fix locally for now, but a fix for this would be very much appreciated.
If anyone is wondering about the use case for this, I'm working on an enterprise level JSON based medical API. I'm composing together input filters from my various Doctrine entities (using the AnnotationBuilder) to allow nested POST operations.
I noticed, that my form was not validating correctly. After some digging in code, I found, that although inputSpec is properly set in ElementAnnotationsListener::handleComposedObjectAnnotation, it gets ignored in AnnotationBuilder::configureElement
So here is what I found was causing it, and how I fixed it (although I am not sure, if that is correct):
AnnotationBulder.php:
ElementAnnotationsListener.php:
I don't believe that this is expected behavior, because every other aspect of the element configuration can be set in ElementAnnotationsListener::handleComposedObjectAnnotation.
Originally posted by @prendit at zendframework/zend-form#125
The text was updated successfully, but these errors were encountered: