Skip to content

Commit

Permalink
Fixed getExtendedType compatibility for symfony >= 2.8 (#4444)
Browse files Browse the repository at this point in the history
* Fixed getExtendedType compatibility for symfony >= 2.8

* Updated unit tests for ChoiceTypeExtension

* Added NEXT_MAJOR comments

* Updated php comments that were added as phpDoc
  • Loading branch information
eduardoconceicao authored and jordisala1991 committed Apr 6, 2017
1 parent ef0d61e commit f703676
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
12 changes: 8 additions & 4 deletions Form/Extension/ChoiceTypeExtension.php
Expand Up @@ -56,12 +56,16 @@ public function buildView(FormView $view, FormInterface $form, array $options)
}

/**
* Returns the name of the type being extended.
*
* @return string The name of the type being extended
* {@inheritdoc}
*/
public function getExtendedType()
{
return 'choice';
/*
* NEXT_MAJOR: Remove when dropping Symfony <2.8 support. It should
* simply be return 'Symfony\Component\Form\Extension\Core\Type\ChoiceType';
*/
return method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')
? 'Symfony\Component\Form\Extension\Core\Type\ChoiceType'
: 'choice';
}
}
Expand Up @@ -58,12 +58,16 @@ public function buildView(FormView $view, FormInterface $form, array $options)
}

/**
* Returns the name of the type being extended.
*
* @return string The name of the type being extended
* {@inheritdoc}
*/
public function getExtendedType()
{
return 'form';
/*
* NEXT_MAJOR: Remove when dropping Symfony <2.8 support. It should
* simply be return 'Symfony\Component\Form\Extension\Core\Type\FormType';
*/
return method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')
? 'Symfony\Component\Form\Extension\Core\Type\FormType'
: 'form';
}
}
18 changes: 17 additions & 1 deletion Tests/Form/Extension/ChoiceTypeExtensionTest.php
Expand Up @@ -62,7 +62,23 @@ public function testExtendedType()
{
$extension = new ChoiceTypeExtension();

$this->assertSame('choice', $extension->getExtendedType());
/*
* NEXT_MAJOR: Remove when dropping Symfony <2.8 support. It should
* simply be:
*
* $this->assertSame(
* 'Symfony\Component\Form\Extension\Core\Type\ChoiceType',
* $extension->getExtendedType()
* );
*/
if (method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')) {
$this->assertSame(
'Symfony\Component\Form\Extension\Core\Type\ChoiceType',
$extension->getExtendedType()
);
} else {
$this->assertSame('choice', $extension->getExtendedType());
}
}

public function testDefaultOptionsWithSortable()
Expand Down

0 comments on commit f703676

Please sign in to comment.