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