public function UsersForm::submitForm in Notify 2.0.x
Same name and namespace in other branches
- 8 src/Form/UsersForm.php \Drupal\notify\Form\UsersForm::submitForm()
- 1.0.x src/Form/UsersForm.php \Drupal\notify\Form\UsersForm::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 ConfigFormBase::submitForm
File
- src/
Form/ UsersForm.php, line 139
Class
- UsersForm
- Defines a form that configures forms module settings.
Namespace
Drupal\notify\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$db_connection = \Drupal::database();
$config = $this
->config('notify.settings');
$values = $form_state
->getValues();
if (isset($values['bulk']) && 1 == $values['bulk']) {
$node = $config
->get('notify_def_node');
$comment = $config
->get('notify_def_comment');
// Get uids of non-subscribers from {notify}.
$r = $db_connection
->select('notify', 'n');
$r
->fields('n', [
'uid',
]);
$r
->condition('n.status', 0, '=');
$result = $r
->execute();
foreach ($result as $user) {
$db_connection
->update('notify')
->fields([
'status' => 1,
'node' => $node,
'comment' => $comment,
'attempts' => 0,
])
->condition('uid', $user->uid, '=')
->execute();
}
}
elseif (!array_key_exists('settings', $values)) {
$this->messenger
->addMessage($this
->t('No users have notifications enabled.'), 'warning');
return;
}
if (isset($values['settings']['table']) && $values['settings']['table']) {
foreach ($values['settings']['table'] as $uid => $settings) {
$db_connection
->update('notify')
->fields([
'node' => $settings['node'],
'comment' => $settings['comment'],
])
->condition('uid', $uid)
->execute();
}
}
$this->messenger
->addMessage($this
->t('Users notify settings saved.'));
}