Symfony FormType在更新到2.8之后包含1个抽象方法


The Symfony FormType contains 1 abstract method after update to 2.8

我最近刚刚更新到2.8,现在在调用Form Factory的创建函数时出现以下错误。

Error: Class Symfony'Component'Form'Extension'Core'Type'FormType contains 1 
abstract method and must therefore be declared abstract or implement the 
remaining methods (Symfony'Component'Form'FormTypeInterface::setDefaultOptions)

FormFactory的调用如下:

$this->formFactory->create(
        get_class(new ProductType()),
        $product,
        [
            'method' => 'POST',
            'type' => $type,
            'locales' => $context->shop->getLocales(),
            'product' => $product,
            'numberDataTransformer' => $this->numberTransformerFactory->createFromLocale(
                $context->user->getLocale(),
                $context->shop->getDefaultLocale()
            ),
            'priceType' => $context->shop->getConfiguration()->getProductConfiguration()->getPricesBackend(),
            'isShortDescriptionEnabled' => $context->shop->getConfiguration()->getProductConfiguration()->isShortDescriptionEnabled()
        ]);

我尝试了几种方法将ProductType传递给函数,但似乎都不起作用。我总是得到两个结果中的一个:要么是找不到类型,要么是返回FormType没有实现setDefaultOptions的错误。

我错过了什么?

编辑:

这里有一些附加代码:

formFactory参数的声明:

public function __construct(Request $request, FormFactoryInterface $formFactory)
{
    $this->request = $request;
    $this->formFactory = $formFactory;
}

ProductType类

<?php
namespace CustomNamespace'BackendBundle'Product'Form;
use CustomNamespace'BackendBundle'Common'NumberDataTransformer;
use Symfony'Component'Form'AbstractType;
use Symfony'Component'Form'FormBuilderInterface;
use Symfony'Component'OptionsResolver'OptionsResolverInterface;
use Symfony'Component'OptionsResolver'OptionsResolver;
use CustomNamespace'BackendBundle'Product'Form'ImageType;
use ShopwareEasy'BackendBundle'Product'Form'AttachmentType;
use Symfony'Component'Validator'Exception'InvalidOptionsException;
/**
 * Form element type for products.
 */
class ProductType extends AbstractType
{
    /**
     * @var string
     */
    private $method;
    /**
     * @var string
     */
    private $type;
    /**
     * @var array
     */
    private $locales;
    /**
     * @var Product
     */
    private $product;
    /**
     * @var 'CustomNamespace'BackendBundle'Common'NumberDataTransformer
     */
    private $numberDataTransformer;
    /**
     * @var string
     */
    private $priceType;
    /**
     * @var bool
     */
    private $isShortDescriptionEnabled;
    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     * @return void
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        parent::buildForm($builder, $options);
        $builder->setMethod($this->method);
        $regionType = new RegionShippingTimeType();
        if ($this->type == 'download') {
            $regionType->enableForDownloadableProduct();
        }
        $builder->add('regions', 'collection', array(
            'type'   => $regionType,
            'label' => false,
            'options'  => array(
                'required'  => false,
                'attr'      => array('class' => 'email-box')
            ),
        ));
        $builder->add('vendor', 'text', ['label' => 'form_product_vendor']);
        if ($this->type == 'normal') {
            $builder->add(
                'mainVariant',
                new MainVariantNormalType(
                    $this->method,
                    $this->locales,
                    $this->product,
                    $this->numberDataTransformer,
                    $this->priceType,
                    $this->isShortDescriptionEnabled
                ),
                ['error_bubbling' => false, 'label' => false]
            );
        } elseif ($this->type == 'download') {
            $builder->add(
                'mainVariant',
                new MainVariantDownloadType(
                    $this->method,
                    $this->locales,
                    $this->product,
                    $this->numberDataTransformer,
                    $this->priceType,
                    $this->isShortDescriptionEnabled
                ),
                ['error_bubbling' => false, 'label' => false]
            );
        } elseif ($this->type == 'variant') {
            $builder->add(
                'mainVariant',
                new MainVariantVariantType(
                    $this->method,
                    $this->locales,
                    $this->product,
                    $this->numberDataTransformer,
                    $this->priceType,
                    $this->isShortDescriptionEnabled
                ),
                ['error_bubbling' => false, 'label' => false]
            );
        }
        if ($this->method == 'PUT') {
            $builder->add(
                'images',
                new ImageType(),
                ['error_bubbling' => true, 'label' => false]
            );
            $builder->add(
                'attachments',
                new AttachmentType(),
                ['error_bubbling' => true, 'label' => false]
            );
        }
    }
    /**
     * @param 'Symfony'Component'OptionsResolver'OptionsResolverInterface $resolver
     */
    public function configureOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(
            array(
                'data_class' => 'CustomNamespace''BackendBundle''Product''Product',
                'csrf_protection' => false,
                'error_bubbling' => false,
                'cascade_validation' => true,
                'method' => 'POST',
                'type' => 'normal'
            )
        );
        parent::configureOptions($resolver);
    }
    public function setDefaultOptions(OptionsResolverInterface $resolver) {
        /** @var OptionResolver $resolver */
        $this->configureOptions($resolver);
    }
    public function getName() {
        return get_class($this);
    }
}

问题是由根本没有更新的文件产生的。。setDefaultOptions的实现应该仍然存在于Symfony 2.8类中,但它们没有。在摧毁了我的流浪汉并重新创造了它之后,一切都很顺利。

但是感谢大家的帮助!