You are here

public function HubspotWebformHandler::submitConfigurationForm in HubSpot 8

Same name and namespace in other branches
  1. 3.x src/Plugin/WebformHandler/HubspotWebformHandler.php \Drupal\hubspot\Plugin\WebformHandler\HubspotWebformHandler::submitConfigurationForm()

Form submission handler.

Parameters

array $form: An associative array containing the structure of the plugin form as built by static::buildConfigurationForm().

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

Overrides WebformHandlerBase::submitConfigurationForm

File

src/Plugin/WebformHandler/HubspotWebformHandler.php, line 240

Class

HubspotWebformHandler
Webform submission remote post handler.

Namespace

Drupal\hubspot\Plugin\WebformHandler

Code

public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
  if (!$this->hubspot
    ->isConfigured()) {
    return;
  }
  $hubspot_id = $form_state
    ->getValues()['mapping']['hubspot_form'];
  $fields = $form_state
    ->getValues()['mapping']['field_group']['fields'];
  $settings = [];

  // Add new field mapping.
  if ($hubspot_id != '--donotmap--') {
    $settings['form_guid'] = $hubspot_id;
    $settings['field_mapping'] = array_filter($fields, function ($hubspot_field) {
      return $hubspot_field !== '--donotmap--';
    });
    $this
      ->messenger()
      ->addMessage($this
      ->t('Saved new field mapping.'));
  }
  $this
    ->setSettings($settings);
}