Interim commit.
[yaffs-website] / web / modules / contrib / hacked / src / Form / HackedSettingsForm.php
1 <?php
2 /**
3  * @file
4  * Contains \Drupal\hacked\Form\HackedSettingsForm.
5  */
6
7 namespace Drupal\hacked\Form;
8
9 use Drupal\Component\Utility\Html;
10 use Drupal\Core\Form\ConfigFormBase;
11 use Drupal\Core\Form\FormStateInterface;
12
13 /**
14  * Configure locale settings for this site.
15  */
16 class HackedSettingsForm extends ConfigFormBase {
17   /**
18    * {@inheritdoc}
19    */
20   protected function getEditableConfigNames() {
21     return ['hacked.settings'];
22   }
23
24   /**
25    * {@inheritdoc}
26    */
27   public function getFormID() {
28     return 'hacked_settings';
29   }
30
31   /**
32    * {@inheritdoc}
33    */
34   public function buildForm(array $form, FormStateInterface $form_state) {
35     $config = $this->config('hacked.settings');
36
37     $hashers = hacked_get_file_hashers();
38
39     $form['selected_file_hasher'] = array(
40       '#type' => 'details',
41       '#title' => t('File hasher'),
42       '#open' => TRUE,
43     );
44
45     $parents = array('selected_file_hasher');
46
47     foreach ($hashers as $name => $hasher_info) {
48       // Generate the parents as the autogenerator does, so we will have a
49       // unique id for each radio button.
50       $parents_for_id = array_merge($parents, array($name));
51       $form['selected_file_hasher'][$name] = array(
52         '#type' => 'radio',
53         '#title' => $hasher_info['name'],
54         '#default_value' => $config->get('selected_file_hasher'),
55         '#return_value' => $name,
56         '#parents' => $parents,
57         '#description' => !empty($hasher_info['description']) ? $hasher_info['description'] : '',
58         '#id' => Html::getId('edit-' . implode('-', $parents_for_id)),
59       );
60     }
61
62     return parent::buildForm($form, $form_state);
63   }
64
65   /**
66    * {@inheritdoc}
67    */
68   public function submitForm(array &$form, FormStateInterface $form_state) {
69     // Clear the Hacked! report cache.
70 //    cache_clear_all('hacked:full-report', HACKED_CACHE_TABLE);
71
72     $values = $form_state->getValues();
73
74     $config = $this->config('hacked.settings');
75     $config->set('selected_file_hasher', $values['selected_file_hasher'])
76       ->save();
77
78     parent::submitForm($form, $form_state);
79   }
80
81 }