Search code examples
silex

Error with forms after composer update


After an update with composer, i have this problem on my forms.

[2017-06-26 10:35:26] MicroCMS.CRITICAL: Symfony\Component\Form\Exception\UnexpectedTypeException: Expected argument of type "string", "MicroCMS\Form\Type\NewsletterType" given (uncaught exception) at S:\wamp\www\silex\vendor\symfony\form\FormFactory.php line 55 {"exception":"[object] (Symfony\\Component\\Form\\Exception\\UnexpectedTypeException(code: 0): Expected argument of type \"string\", \"MicroCMS\\Form\\Type\\NewsletterType\" given at S:\\wamp\\www\\silex\\vendor\\symfony\\form\\FormFactory.php:55)"} []

He asks me for a string while it is an object he needs.

I put the code of a form, I have the same problem with all:

<?php

namespace MicroCMS\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Validator\Constraints as Assert;

class NewsletterType extends AbstractType
{

public function buildForm(FormBuilderInterface $builder, array $options)     {
    $builder->add('email', EmailType::class, [
        'label'       => '',
        'required'    => true,
        'attr'        => ['autocomplete' => 'off'],
        'constraints' => new Assert\Email(['checkMX' => true]),
    ]);
}

public function getName() {
    return 'newsletter';
}

}

Thank you for your help.


Solution

  • I think that you pass FormType object instead of FormType class name. Find code where you create this form and change it to:

    $app['form.factory']->create(\MicroCMS\Form\Type\NewsletterType::class