Skip to content

Instantly share code, notes, and snippets.

@ryanotella
Last active December 3, 2015 01:29
Show Gist options
  • Select an option

  • Save ryanotella/466f861348249cf335eb to your computer and use it in GitHub Desktop.

Select an option

Save ryanotella/466f861348249cf335eb to your computer and use it in GitHub Desktop.
Order Customer Selector with optional exclusion of archived contacts
<?php
class Contact
{
/* @var Order[] */
private $orders;
/** @var bool */
private $deleted;
// ...
}
<?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.
)
);
}
}
<?php
class Order
{
/* @var Contact */
private $customer;
// ...
}
<?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