You are here

public function WebformMailChimpHandler::submitConfigurationForm in Webform Mailchimp 8.5

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/WebformMailChimpHandler.php, line 235

Class

WebformMailChimpHandler
Form submission to MailChimp handler.

Namespace

Drupal\webform_mailchimp\Plugin\WebformHandler

Code

public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
  parent::submitConfigurationForm($form, $form_state);
  $values = $form_state
    ->getValues();
  foreach ($this->configuration as $name => $value) {
    if (isset($values['mailchimp'][$name])) {

      // Filter out unset interest group ids so mailchimp_subscribe_process()
      // doesn't subscribe all groups.
      if ($name == 'interest_groups') {
        if (!empty($values['mailchimp'][$name])) {
          $filtered_groups = [];
          foreach ($values['mailchimp'][$name] as $group_id => $interest_group) {
            if ($group_subcriptions = array_filter($interest_group)) {
              $filtered_groups[$group_id] = $group_subcriptions;
            }
          }
          $this->configuration[$name] = $filtered_groups;
        }
      }
      else {
        $this->configuration[$name] = $values['mailchimp'][$name];
      }
    }
  }
}