Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class CustomerInformation extends AbstractType
- {
- /**
- * @var Translator $translator
- */
- private $translator;
- public function __construct(
- Translator $translator
- ) {
- $this->translator = $translator;
- }
- public function buildForm(FormBuilderInterface $builder, array $options)
- {
- $builder->addEventListener(
- FormEvents::PRE_SUBMIT,
- [$this, 'onPreSubmit']
- );
- }
- public function onPreSubmit(FormEvent $event)
- {
- $data = $event->getData();
- $form = $event->getForm();
- if (!empty($data['customerId'])) {
- // ...
- if (count($customer->customerPriceLists()) === 0) {
- $form->addError(new FormError($this->translator->trans(
- 'No price list linked from QSP to customer.',
- [],
- $form->getConfig()->getOption('translation_domain')
- )));
- }
- }
- }
- public function configureOptions(OptionsResolver $resolver)
- {
- $resolver->setDefaults([
- 'translation_domain' => 'order_entry'
- ]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement