Skip to content

Instantly share code, notes, and snippets.

@weaverryan
Created January 17, 2018 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weaverryan/e8a6d3c3a9ecf2b6d46e937e8dd98ec4 to your computer and use it in GitHub Desktop.
Save weaverryan/e8a6d3c3a9ecf2b6d46e937e8dd98ec4 to your computer and use it in GitHub Desktop.
<?php
class MyController
{
public function someAction()
{
$form = $this->createForm(MyCustomFormType::class, $someEntityOrNull, [
'entity_user_option' => 'some_value',
]);
$form2 = $this->createForm(MyCustomFormType::class, $someEntityOrNull, [
'entity_user_option' => 'some_other_value',
]);
}
}
<?php
// ...
clas MyCustomFromType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
// fetch the option here and use it to do different things in your form
$entityUserOption = $options['entity_user_option'];
}
public function configureOptions(OptionsResolver $resolver)
{
// this makes it legal to have this option
$resolver->setRequired(['entity_user_option']);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment