Last active
December 3, 2015 01:29
-
-
Save ryanotella/466f861348249cf335eb to your computer and use it in GitHub Desktop.
Order Customer Selector with optional exclusion of archived contacts
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 | |
| class Contact | |
| { | |
| /* @var Order[] */ | |
| private $orders; | |
| /** @var bool */ | |
| private $deleted; | |
| // ... | |
| } |
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 | |
| class ContactSelectorType extends AbstractType | |
| { | |
| public function getName() | |
| { | |
| return 'contact_selector'; | |
| } | |
| public function getParent() | |
| { | |
| return 'choice'; | |
| } | |
| public function configureOptions(OptionsResolver $resolver) | |
| { | |
| $resolver->setDefaults( | |
| array( | |
| 'include_deleted' => true, | |
| // Something that will filter out 'deleted' Contacts, | |
| // but always include the current Order contact. | |
| // Should it be 'choice_list', 'choice_loader', 'choices' ...? | |
| // | |
| // Or entirely override buildView()... | |
| // | |
| // A form listener in the OrderType, could add the selector field with custom data | |
| // but that increases the coupling beyond what should be necessary. | |
| ) | |
| ); | |
| } | |
| } |
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 | |
| class Order | |
| { | |
| /* @var Contact */ | |
| private $customer; | |
| // ... | |
| } |
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 | |
| class OrderType extends AbstractType | |
| { | |
| public function buildForm(FormBuilderInterface $builder, array $options) | |
| { | |
| $builder->add('customer', new ContactSelectorType(), array('include_deleted' => false)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment