Michi
Michi

Reputation: 2520

::buildView() must be compatible with that of Symfony\Component\Form\FormTypeInterface::buildView()

I'm trying to implement a custom field type for my Symfony2 forms but for whatever reason I'm getting a fatal error as said in the title of this question.
I already copied over the original declaration from the interface, but to no avail :-(

<?php
namespace Yanic\HomeBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormError;
use Symfony\Component\Form\CallbackValidator;
use Symfony\Component\Form\FormValidatorInterface;

class ShowOnlyType extends AbstractType
{
/**
     * {@inheritdoc}
     */
    function buildView(FormViewInterface $view, FormInterface $form, array $options)
    {
        $view->addVars(array(
            'value'   => date( 'd/m/Y H:i', $options['value'] )
        ));
    }

    /**
    * {@inheritdoc}
    */
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {

        $resolver->setDefaults(array(
                'data_class' => 'DateTime'
        ));
    }

    public function getParent()
    {
        return 'form';
    }

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

Thanks for any help

Upvotes: 0

Views: 3685

Answers (1)

Marco
Marco

Reputation: 226

Here is an answer that should solve your problem.

The reason most probably that you haven't use the required param type.

use Symfony\Component\Form\AbstractType,
use Symfony\Component\Form\FormViewInterface;
use Symfony\Component\Form\FormInterface;

//...
class SomeType extends AbstractType
{
    public function buildView(FormViewInterface $view, FormInterface $form, array $options)
}

Upvotes: 8

Related Questions