You are here

public function RuleForm::submitForm in CRM Core 8

Same name and namespace in other branches
  1. 8.3 modules/crm_core_user_sync/src/Form/RuleForm.php \Drupal\crm_core_user_sync\Form\RuleForm::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

modules/crm_core_user_sync/src/Form/RuleForm.php, line 106

Class

RuleForm
Configure CRM Core User Synchronization settings for this site.

Namespace

Drupal\crm_core_user_sync\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $rule = $form_state
    ->get('rule');
  foreach ([
    'role',
    'contact_type',
    'weight',
    'enabled',
  ] as $key) {
    $rule[$key] = $form_state
      ->getValue($key);
  }
  $rules = $this
    ->config('crm_core_user_sync.settings')
    ->get('rules');
  $rule_key = $form_state
    ->get('rule_key');
  if ($rule_key === 'new') {
    $rules[] = $rule;
  }
  else {
    $rules[$rule_key] = $rule;
  }
  $this
    ->config('crm_core_user_sync.settings')
    ->set('rules', $rules)
    ->save();
  $form_state
    ->setRedirect('crm_core_user_sync.config');
  parent::submitForm($form, $form_state);
}