Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
26 / 26
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
SettingsForm
100.00% covered (success)
100.00%
26 / 26
100.00% covered (success)
100.00%
4 / 4
4
100.00% covered (success)
100.00%
1 / 1
 getFormId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getEditableConfigNames
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 buildForm
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
1 / 1
1
 submitForm
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Drupal\name\Form;
6
7use Drupal\Core\Form\ConfigFormBase;
8use Drupal\Core\Form\FormStateInterface;
9
10/**
11 * Configure name settings for this site.
12 */
13class SettingsForm extends ConfigFormBase {
14
15  /**
16   * {@inheritdoc}
17   */
18  public function getFormId() {
19    return 'name_admin_settings';
20  }
21
22  /**
23   * {@inheritdoc}
24   */
25  protected function getEditableConfigNames() {
26    return ['name.settings'];
27  }
28
29  /**
30   * {@inheritdoc}
31   */
32  public function buildForm(array $form, FormStateInterface $form_state) {
33    $config = $this->configFactory->get('name.settings');
34
35    $form['name_settings'] = ['#tree' => TRUE];
36    $form['name_settings']['sep1'] = [
37      '#type' => 'textfield',
38      '#title' => $this->t('Separator 1 replacement token'),
39      '#default_value' => $config->get('sep1'),
40    ];
41    $form['name_settings']['sep2'] = [
42      '#type' => 'textfield',
43      '#title' => $this->t('Separator 2 replacement token'),
44      '#default_value' => $config->get('sep2'),
45    ];
46    $form['name_settings']['sep3'] = [
47      '#type' => 'textfield',
48      '#title' => $this->t('Separator 3 replacement token'),
49      '#default_value' => $config->get('sep3'),
50    ];
51
52    return parent::buildForm($form, $form_state);
53  }
54
55  /**
56   * {@inheritdoc}
57   */
58  public function submitForm(array &$form, FormStateInterface $form_state) {
59    $this->config('name.settings')
60      ->set('sep1', $form_state->getValue(['name_settings', 'sep1']))
61      ->set('sep2', $form_state->getValue(['name_settings', 'sep2']))
62      ->set('sep3', $form_state->getValue(['name_settings', 'sep3']))
63      ->save();
64
65    parent::submitForm($form, $form_state);
66  }
67
68}