0

When I visit my browser this is what i get:

Fatal error: Declaration of Ecs\CrmBundle\Form\Parts\DepartmentSelectionType::getDefaultOptions() must be compatible with Symfony\Component\Form\FormTypeInterface::getDefaultOptions() in C:\wamp\www\crm\src\Ecs\CrmBundle\Form\Parts\DepartmentSelectionType.php on line 41

And the file that it is referencing there is found below:

<?php

namespace Ecs\CrmBundle\Form\Parts;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;


class DepartmentSelectionType extends AbstractType {
    private $canSeeAll = false;

    public function __construct($canSeeAll = false)
    {
        $this->canSeeAll = $canSeeAll;
    }

    public function buildForm(FormBuilder $builder, array $options)
    {
        $builder
            ->add('department', 'entity',
                array(
                    'class' => "EcsAgentManagerBundle:EmployeeDepartment",
                    'required' => false,
                    'multiple' => true,
                    'expanded' => true,
                    'label' => "Department"))
        ;
    }

    public function getDefaultOptions(array $options)
    {
        return array(
            'data_class' => 'Ecs\AgentManagerBundle\Entity\EmployeeDepartment',
        );
    }

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

is the file that it is referencing... Any ideas on what the issue can be?

1 Answer 1

1

I believe the FormTypeInterface has changed in Symfony 2.1.

getDefaultOptions no longer takes an argument.

From the UPGRADE-2.1 document:


The methods getDefaultOptions() and getAllowedOptionValues() of form types no longer receive an option array.

You can specify options that depend on other options using closures instead.

Before:

public function getDefaultOptions(array $options)
{
    $defaultOptions = array();

    if ($options['multiple']) {
        $defaultOptions['empty_data'] = array();
    }

    return $defaultOptions;
}

After:

public function getDefaultOptions()
{
    return array(
        'empty_data' => function (Options $options, $previousValue) {
            return $options['multiple'] ? array() : $previousValue;
        }
    );
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.