/** * @param Contact $contact * @return bool * @throws APIException * @throws \Exception */ public function persist(Contact $contact) { $data = $contact->toGandiArray(); if ($contact->isNew()) { $response = $this->gandi->create($this->api_key, $data); if (is_array($response)) { return $response['handle']; } else { throw new APIException("Cannot create contact."); } } else { $handle = $contact->getHandle(); $response = $this->gandi->update($this->api_key, $handle, $data); if (is_array($response)) { return true; } else { throw new \Exception("Cannot update contact."); } } }
/** * @param FormBuilderInterface $builder * @param array $options */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('type', 'choice', array('label' => 'contact.label.type', 'choices' => Contact::getTypes()))->add('firstname', 'text', array('label' => 'contact.label.firstname', 'required' => true))->add('lastname', 'text', array('label' => 'contact.label.lastname', 'required' => true))->add('street', 'textarea', array('label' => 'contact.label.street', 'required' => true))->add('zip', 'text', array('label' => 'contact.label.zip', 'required' => true))->add('city', 'text', array('label' => 'contact.label.city', 'required' => true))->add('country', 'country', array('label' => 'contact.label.country', 'required' => true))->add('email', 'email', array('label' => 'contact.label.email', 'required' => true))->add('phone', 'text', array('label' => 'contact.label.phone', 'required' => true))->add('mobile', 'text', array('label' => 'contact.label.mobile', 'required' => false))->add('fax', 'text', array('label' => 'contact.label.fax', 'required' => false))->add('language', 'language', array('label' => 'contact.label.language', 'required' => false)); //extra parameters $builder->add('extra_parameters', 'collection', array('type' => 'text', 'label' => 'contact.label.extra_parameters', 'options' => array('required' => false, 'allow_add' => true, 'allow_delete' => true, 'options' => array('choices' => Contact::getExtraParametersTypes())))); //password if new if (null === $builder->getData()->getHandle()) { $builder->add('password', 'password', array('required' => true, 'label' => 'contact.label.password')); } $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) { $form = $event->getForm(); $data = $event->getData(); if (Contact::TYPE_PERSON !== $data->getType()) { $form->add('company', 'text', array('required' => true, 'label' => 'contact.label.company')); $form->add('vat_number', 'text', array('required' => false, 'label' => 'contact.label.vat_number')); } }); }