Есть кастом модуль с формой в drupal 8. Нужно сделать, чтобы при отправке формы создавался новый контакт на сайте hubspot.com. Читала документацию [URL]https://developers.hubspot.com/docs/methods/contacts/create_or_update[/URL] Как я понимаю, нужно создать пост запрос на [URL]https://api.hubapi.com/contact...e/email/testingapis@hubspot.com/?hapikey=demo[/URL], где подставить свой hapikey и почту заменить выражением, достающим емэйл введенный в форму. Не понимаю, как правильно передать параметры необходимые для создания контакта (имя,фамилия) и как вообще все это реализовать. Помогите, пожалуйтса... my_form.info.yml name:'My Form' description:'Example create form in Drupal 8' core:8.x type:module my_form.routing.yml my_form.example_form: path:'/my-form' defaults: _form: '\Drupal\my_form\Form\MyForm' _title:'My form' requirements: _permission:'access content' MyForm.php <?php namespaceDrupal\my_form\Form; useDrupal\Core\Form\FormBase; useDrupal\Core\Form\FormStateInterface; classMyFormextendsFormBase{ publicfunction getFormId(){ return'my_form'; } publicfunction buildForm(array $form,FormStateInterface $form_state){ $form['name']= array( '#type'=>'textfield', '#title'=>'First name', '#required'=> TRUE ); $form['first_name']= array( '#type'=>'textfield', '#title'=>'Last name', '#required'=> TRUE ); $form['last_name']= array( '#type'=>'textfield', '#title'=>'Subject', '#required'=> TRUE ); $form['message']= array( '#type'=>'textarea', '#title'=>'Message', '#required'=> TRUE ); $form['email']= array( '#type'=>'email', '#title'=> $this->t('Your e-mail address'), '#required'=> TRUE ); $form['button']= array( '#type'=>'submit', '#value'=>'Submit' ); return $form; } publicfunction validateForm(array &$form,FormStateInterface $form_state){ if(strpos($form_state->getValue('email'),'.com')=== FALSE){ $form_state->setErrorByName('email','E-mail is incorrect!'); } } publicfunction submitForm(array &$form,FormStateInterface $form_state){ $message = $form_state->getValue('message'); $message = wordwrap($message,70,"\r\n"); $subject = $form_state->getValue('subject'); $res = mail('admin@mail.ru', $subject, $message); if($res){ \Drupal::logger('my_form')->notice('Mail is sent. E-mail: '.$form_state->getValue('email')); drupal_set_message('E-mail is sent!'); } } }
вопрос решен $email = $form_state->getValue('email'); $firstname = $form_state->getValue('first_name'); $lastname = $form_state->getValue('last_name'); $url = "https://api.hubapi.com/contacts/v1/contact/createOrUpdate/email/".$email."/?hapikey=62c6e162-1f3e-40eb-aa07-************"; $data = array( 'properties' => [ [ 'property' => 'firstname', 'value' => $firstname ], [ 'property' => 'lastname', 'value' => $lastname ] ] ); $json = json_encode($data,true); $response = \Drupal::httpClient()->post($url.'&_format=hal_json', [ 'headers' => [ 'Content-Type' => 'application/json' ], 'body' => $json ]);