public function SettingsForm::submitForm in CiviCRM Cron 8
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/ SettingsForm.php, line 130
Class
- SettingsForm
- Class SettingsForm.
Namespace
Drupal\civicrm_cron\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this
->config('civicrm_cron.settings');
$config
->set('sitekey', $form_state
->getValue('sitekey'));
// Update authentication credentials, if supplied.
$username = $form_state
->getValue('username');
$password = $form_state
->getValue('password');
if ($username && $password) {
$config
->set('username', $username)
->set('password', $password);
}
$config
->save();
parent::submitForm($form, $form_state);
// CiviMail job is the only job appears to be the only job that requires
// authentication added username and pass back to resolve
// https://drupal.org/node/2088595
if ($username) {
$account = user_load_by_name($username);
if ($account && $account
->hasPermission('view all contacts') && $account
->hasPermission('access CiviCRM') && $account
->hasPermission('access CiviMail')) {
drupal_set_message($this
->t('User has correct permissions to run CiviMail job.'));
}
else {
drupal_set_message($this
->t('User does NOT have correct permissions to run CiviMail job.'), 'error');
}
}
// Test running cron to see if it works.
try {
$this->cronRunner
->runCron();
drupal_set_message($this
->t('CiviCRM Cron Successfully Ran'));
} catch (\Exception $e) {
drupal_set_message($e
->getMessage(), 'error');
}
}