Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
41 / 41 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| UserContactSettingsForm | |
100.00% |
41 / 41 |
|
100.00% |
4 / 4 |
4 | |
100.00% |
1 / 1 |
| getFormId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getEditableConfigNames | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| buildForm | |
100.00% |
31 / 31 |
|
100.00% |
1 / 1 |
1 | |||
| submitForm | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Drupal\crm\Form; |
| 4 | |
| 5 | use Drupal\Core\Form\ConfigFormBase; |
| 6 | use Drupal\Core\Form\FormStateInterface; |
| 7 | |
| 8 | /** |
| 9 | * CRM User Contact settings form. |
| 10 | */ |
| 11 | class UserContactSettingsForm extends ConfigFormBase { |
| 12 | |
| 13 | /** |
| 14 | * {@inheritdoc} |
| 15 | */ |
| 16 | public function getFormId() { |
| 17 | return 'crm_user_contact_settings'; |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * {@inheritdoc} |
| 22 | */ |
| 23 | protected function getEditableConfigNames() { |
| 24 | return [ |
| 25 | 'crm.user_contact.settings', |
| 26 | ]; |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * {@inheritdoc} |
| 31 | */ |
| 32 | public function buildForm(array $form, FormStateInterface $form_state) { |
| 33 | $form = parent::buildForm($form, $form_state); |
| 34 | $settings = $this->config('crm.user_contact.settings'); |
| 35 | $form['display_name'] = [ |
| 36 | '#type' => 'checkbox', |
| 37 | '#title' => $this->t('Display name'), |
| 38 | '#default_value' => $settings->get('display_name'), |
| 39 | '#description' => $this->t('Override the User name with the CRM name.'), |
| 40 | ]; |
| 41 | |
| 42 | $form['create_event'] = [ |
| 43 | '#type' => 'details', |
| 44 | '#title' => $this->t('Create event'), |
| 45 | '#open' => TRUE, |
| 46 | ]; |
| 47 | |
| 48 | $form['create_event']['auto_create_crm_user_contact'] = [ |
| 49 | '#type' => 'checkbox', |
| 50 | '#title' => $this->t('Create CRM user contact automatically'), |
| 51 | '#default_value' => $settings->get('auto_create_crm_user_contact'), |
| 52 | '#description' => $this->t('Automatically create a contact when a user is created.'), |
| 53 | ]; |
| 54 | |
| 55 | $form['create_event']['auto_create_lookup_contact'] = [ |
| 56 | '#type' => 'checkbox', |
| 57 | '#title' => $this->t('Lookup contact automatically'), |
| 58 | '#default_value' => $settings->get('auto_create_lookup_contact'), |
| 59 | '#description' => $this->t('Automatically create a lookup contact when a user is created.'), |
| 60 | '#states' => [ |
| 61 | 'enabled' => [ |
| 62 | ':input[name="auto_create_crm_user_contact"]' => ['checked' => TRUE], |
| 63 | ], |
| 64 | ], |
| 65 | ]; |
| 66 | |
| 67 | return $form; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * {@inheritdoc} |
| 72 | */ |
| 73 | public function submitForm(array &$form, FormStateInterface $form_state) { |
| 74 | |
| 75 | $this->config('crm.user_contact.settings') |
| 76 | ->set('display_name', $form_state->getValue('display_name')) |
| 77 | ->set('auto_create_crm_user_contact', $form_state->getValue('auto_create_crm_user_contact')) |
| 78 | ->set('auto_create_lookup_contact', $form_state->getValue('auto_create_lookup_contact')) |
| 79 | ->save(); |
| 80 | |
| 81 | return parent::submitForm($form, $form_state); |
| 82 | } |
| 83 | |
| 84 | } |