public function MailchimpSignupForm::save in Mailchimp 8
Same name and namespace in other branches
- 2.x modules/mailchimp_signup/src/Form/MailchimpSignupForm.php \Drupal\mailchimp_signup\Form\MailchimpSignupForm::save()
Form submission handler for the 'save' action.
Normally this method should be overridden to provide specific messages to the user and redirect the form after the entity has been saved.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
int Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed.
Overrides EntityForm::save
File
- modules/
mailchimp_signup/ src/ Form/ MailchimpSignupForm.php, line 417
Class
- MailchimpSignupForm
- Form controller for the MailchimpSignup entity edit form.
Namespace
Drupal\mailchimp_signup\FormCode
public function save(array $form, FormStateInterface $form_state) {
$mode = $form_state
->getValue('mode');
/* @var $signup \Drupal\mailchimp_signup\Entity\MailchimpSignup */
$signup = $this
->getEntity();
$signup->mode = array_sum($mode);
$mergefields = $form_state
->getValue('mergefields', []);
$mc_lists = $form_state
->getValue('mc_lists') ? $form_state
->getValue('mc_lists') : $signup->mc_lists;
$mergevar_options = $this
->getMergevarOptions($mc_lists);
foreach ($mergefields as $id => $val) {
if ($val) {
// Can't store objects in configuration; serialize this.
$mergefields[$id] = serialize($mergevar_options[$id]);
}
}
// This can occur when the form is submitted without JS enabled.
if (!isset($signup->mergefields)) {
$signup->mergefields['EMAIL'] = TRUE;
}
if (empty($mergefields)) {
$mergefields['EMAIL'] = serialize($mergevar_options['EMAIL']);
}
$signup->settings['mergefields'] = $mergefields;
$signup->settings['description'] = $form_state
->getValue('description');
$signup->settings['doublein'] = $form_state
->getValue('doublein');
$signup->settings['include_interest_groups'] = $form_state
->getValue('include_interest_groups');
$signup->settings['safe_interest_groups'] = $form_state
->getValue('safe_interest_groups');
$signup->settings['configure_groups'] = $form_state
->getValue('configure_groups');
$signup->settings['gdpr_consent'] = $form_state
->getValue('gdpr_consent');
$signup->settings['gdpr_checkbox_label'] = $form_state
->getValue('gdpr_checkbox_label');
$signup->settings['gdpr_consent_required'] = $form_state
->getValue('gdpr_consent_required');
$groups_items = [];
$groups_settings = $form_state
->getValue('groups_container');
if (isset($groups_settings['items'])) {
$signup->settings['group_items'] = $groups_settings['items'];
}
// Clear path value if mode doesn't include signup page.
if (!isset($mode[MAILCHIMP_SIGNUP_PAGE])) {
$signup->settings['path'] = '';
}
$signup
->save();
$this->routerBuilder
->setRebuildNeeded();
$form_state
->setRedirect('mailchimp_signup.admin');
}