public function AuthUnlinkForm::submitForm in Open Social 8
Same name and namespace in other branches
- 8.9 modules/custom/social_auth_extra/src/Form/AuthUnlinkForm.php \Drupal\social_auth_extra\Form\AuthUnlinkForm::submitForm()
- 8.2 modules/custom/social_auth_extra/src/Form/AuthUnlinkForm.php \Drupal\social_auth_extra\Form\AuthUnlinkForm::submitForm()
- 8.3 modules/custom/social_auth_extra/src/Form/AuthUnlinkForm.php \Drupal\social_auth_extra\Form\AuthUnlinkForm::submitForm()
- 8.4 modules/custom/social_auth_extra/src/Form/AuthUnlinkForm.php \Drupal\social_auth_extra\Form\AuthUnlinkForm::submitForm()
- 8.5 modules/custom/social_auth_extra/src/Form/AuthUnlinkForm.php \Drupal\social_auth_extra\Form\AuthUnlinkForm::submitForm()
- 8.6 modules/custom/social_auth_extra/src/Form/AuthUnlinkForm.php \Drupal\social_auth_extra\Form\AuthUnlinkForm::submitForm()
- 8.7 modules/custom/social_auth_extra/src/Form/AuthUnlinkForm.php \Drupal\social_auth_extra\Form\AuthUnlinkForm::submitForm()
- 8.8 modules/custom/social_auth_extra/src/Form/AuthUnlinkForm.php \Drupal\social_auth_extra\Form\AuthUnlinkForm::submitForm()
Form submission handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormInterface::submitForm
File
- modules/
custom/ social_auth_extra/ src/ Form/ AuthUnlinkForm.php, line 68
Class
- AuthUnlinkForm
- Class AuthUnlinkForm.
Namespace
Drupal\social_auth_extra\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$account = User::load($this
->currentUser()
->id());
$network_manager = \Drupal::service('plugin.network.manager');
$is_connected = FALSE;
foreach ($network_manager
->getDefinitions() as $definition) {
/** @var \Drupal\social_auth_extra\UserManagerInterface $user_manager */
$user_manager = \Drupal::service($definition['id'] . '.user_manager');
$user_manager
->setAccount($account);
if ($definition['id'] !== $this->socialNetwork['id'] && $user_manager
->getAccountId()) {
$is_connected = TRUE;
break;
}
}
$user_manager = \Drupal::service($this->socialNetwork['id'] . '.user_manager');
$user_manager
->setAccount($account);
$user_manager
->setAccountId(NULL);
$account
->save();
if ($is_connected) {
drupal_set_message($this
->t('Your @network account is unlinked. You can still log in with your @community_name account.', [
'@network' => $this->socialNetwork['social_network'],
'@community_name' => \Drupal::config('system.site')
->get('name'),
]));
}
else {
drupal_set_message($this
->t('Your @network account is unlinked. Make sure you set a password or connect another social platform. Please enter a password to be able to continue using @community_name.', [
'@network' => $this->socialNetwork['social_network'],
'@community_name' => \Drupal::config('system.site')
->get('name'),
]), 'warning');
}
$form_state
->setRedirect('entity.user.edit_form', [
'user' => $this
->currentUser()
->id(),
]);
}