11.
Form Type Extension Magic
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
Whoops, an error! Please, try again later.
5 Comments
https://knpuniversity.com/s...
I think it will be good to remind about Symfony3.3-like adding service:
AppBundle\Form\TypeExtension\HelpFormExtension:
tags:
- { name: form.type_extension, extended_type: Symfony\Component\Form\Extension\Core\Type\FormType }
maraloon We'll be releasing a whole new suite of Symfony 4 videos soon :). The service name change for Symfony 3.3 was a bit tough - we added a bunch of notes in our older tutorials to make people aware. But mostly, this will be improved with fresh tutorials!
Hi, I get this error at the end:
Type error: Argument 1 passed to Symfony\Component\OptionsResolver\OptionsResolver::setDefaults() must be of the type array, string given, called in C:\Users\John\Documents\Siti\aqua_note\src\AppBundle\Form\TypeExtension\HelpFormExtension.php on line 22
I think It shouldn't be an array because it's a value and its option, what am I doing wrong? Below my code:
namespace AppBundle\Form\TypeExtension;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolver;
class HelpFormExtension extends AbstractTypeExtension
{
public function buildView(FormView $view, FormInterface $form, array $options)
{
if ($options['help']) {
$view->vars['help'] = $options['help'];
}
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults('help', null);
}
public function getExtendedType()
{
return FormType::class;
}
}
Thanks in advance
Solved, I made a stupid typo mistake (setDefaults instead of setDefault) :(
Hey Josh,
Ah, those methods do the same but in a different way, very easy to miss "s" at the end :)
I'm glad you found the problem so quick.
Cheers!
"Houston: no signs of life"
Start the conversation!