Closed rafrsr closed 7 years ago
Me too facing the same problem. I'm using Symfony 2.8.1 . In development environment it works fine. But in production environment it throws error.
The extended type specified for the service "sonata.admin.form.extension.field" does not match the actual extended type. Expected "Symfony\Component\Form\Extension\Core\Type\FormType", given "form".
I'm not dealing with backend interface (not with sonata). This error throws on a simple contact form. My code.
/**
* @Route("/contact", name="fz_contact")
*/
public function contactAction(Request $request) {
$em = $this->getDoctrine()->getManager();
$cnt = $this->getDoctrine()->getRepository('AppBundle:FZPage')->findOneBy(['page' => 'fz_contact']);
$entity = new \AppBundle\Entity\FZContact();
$form = $this->createForm(FZContactType::class, $entity);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entity->setCip($request->getClientIp());
$entity->setCbrowser($request->server->get('HTTP_USER_AGENT'));
$myMailer = $this->get('fz_app.fe.mail.contact');
$result = $myMailer->sendMail($entity, $request->getClientIp(), $request->server->get('HTTP_USER_AGENT'));
$this->flashMSG($result, 'contact');
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('fz_home'));
}
$x = ['cmf' => $cnt, 'pTitle' => 'Contact us'];
return $this->render('frontend/show/index.html.twig', ['x' => $x, 'entity' => $entity, 'form' => $form->createView()]);
}
Form
<?php
namespace AppBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
class FZContactType extends AbstractType {
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder
->add('name', null, ['attr' => ['class' => 'form-control', 'placeholder' => 'Your name']])
->add('email', null, ['attr' => ['class' => 'form-control', 'placeholder' => 'Your email id']])
->add('phone', null, ['attr' => ['class' => 'form-control', 'placeholder' => 'Your contact phone number']])
->add('message', TextareaType::class, ['attr' => ['class' => 'form-control', 'placeholder' => 'The information to be sent']])
;
}
/**
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver) {
$resolver->setDefaults(array(
'data_class' => 'AppBundle\Entity\FZContact'
));
}
}
I have some knowledge in Symfony. I'm using symfony form 1.2 . But i'm not expert in Symfony Core.
I updated my code as per * rafrsr commented on 8 Dec 2015 * , then i get the following error...
The extended type specified for the service "sonata.admin.form.extension.field.mopa" does not match the actual extended type. Expected "Symfony\Component\Form\Extension\Core\Type\FormType", given "form".
What is you version sonata-project/core-bundle?
This should be resolved by this: https://sonata-project.org/bundles/core/master/doc/reference/form_types.html#symfony3-supports
Sonata 2.4 does not exist anymore, reopen if you still have the bug with Sonata 3.
I do still get this error using sonata-project/admin-bundle
/ 3.9
and symfony 3.1.6
.
The exact error message is: The extended type specified for the service "sonata.admin.form.extension.field.mopa" does not match the actual extended type. Expected "Symfony\Component\Form\Extension\Core\Type\FormType", given "form".
In the code of Sonata\AdminBundle\Form\Extension\Field\Type\MopaCompatibilityTypeFieldExtension
i found that getExtendedType
just does return 'form';
.
( https://github.com/sonata-project/SonataAdminBundle/blob/3.9.0/Form/Extension/Field/Type/MopaCompatibilityTypeFieldExtension.php#L69 )
Did i forget to configure something or is this still a bug?
The line you're linking to should read return Symfony\Component\Form\Extension\Core\Type\FormType
when symfony >=2.8 is in use. Can you make a PR?
I am not confident that changing that line is correct. Here is another Example: https://github.com/sonata-project/SonataAdminBundle/blob/3.9.0/Form/Extension/ChoiceTypeExtension.php#L67
I got it running without exception - my error was, that i only registered SonataAdminBundle
. After also registering the other bundles the error is gone.
There seems to be a additional config/mapping for the form types: https://github.com/sonata-project/SonataAdminBundle/blob/3.9.0/Resources/config/form_types.xml#L37
I think this is related, but dont know how ..
I am not confident that changing that line is correct.
You could just try, maybe ?
After also registering the other bundles the error is gone.
Closing this again then.
I tried, but then there was the same exception with the ChoiceType..
Then maybe it needs to be changed too?
Yes - but i am really not so deep into symfony and the config system.. I dont feel like i should make a PR. Maybe this could be some kind of backward compatibility thing for symfony 2.x ..
Ok, drop it then… someone else will surely fix this… surely.
After update a project (with sonata 2.4@dev) to symfony 2.8 got this error
I cannot open any admin page.
Looking for information about symfony changes, I found this:
All sonata fields throw this exception with SF2.8+.
For example
Form/Extension/Field/Type/FormTypeFieldExtension.php
has the following (not compatible with SF2.8+) statement .The proposed trick to keep compatibility backward should be something like:
PHP 5.5+
or (for all PHP versions)