Created
March 17, 2014 20:41
-
-
Save ftdysa/9607913 to your computer and use it in GitHub Desktop.
Injecting services into form types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Project\WebsiteBundle\Form\Type\Payment; | |
use Doctrine\ORM\EntityRepository; | |
use Entity\Core\Account; | |
use Symfony\Component\Form\FormBuilderInterface; | |
use Symfony\Component\Form\FormEvent; | |
use Symfony\Component\Form\FormEvents; | |
use Symfony\Component\OptionsResolver\OptionsResolverInterface; | |
use Symfony\Component\Form\AbstractType; | |
class PaymentType extends AbstractType { | |
private $account; | |
public function __construct(Account $account) { | |
$this->account = $account; | |
} | |
public function buildForm(FormBuilderInterface $builder, array $options) { | |
// stuff with account | |
} | |
public function setDefaultOptions(OptionsResolverInterface $resolver) { | |
$resolver->setDefaults(array( | |
'data_class' => 'Entity\Core\Payment', | |
'cascade_validation' => true | |
)); | |
} | |
public function getName() { | |
return 'payment'; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services: | |
project.form.type.payment: | |
class: Project\WebsiteBundle\Form\Type\Payment\PaymentType | |
arguments: ["@=service('project.helper.user').getAccount()"] | |
tags: | |
- { name: form.type, alias: payment } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment