4 * Contains \Drupal\hacked\Form\HackedSettingsForm.
7 namespace Drupal\hacked\Form;
9 use Drupal\Component\Utility\Html;
10 use Drupal\Core\Form\ConfigFormBase;
11 use Drupal\Core\Form\FormStateInterface;
14 * Configure locale settings for this site.
16 class HackedSettingsForm extends ConfigFormBase {
20 protected function getEditableConfigNames() {
21 return ['hacked.settings'];
27 public function getFormID() {
28 return 'hacked_settings';
34 public function buildForm(array $form, FormStateInterface $form_state) {
35 $config = $this->config('hacked.settings');
37 $hashers = hacked_get_file_hashers();
39 $form['selected_file_hasher'] = array(
41 '#title' => t('File hasher'),
45 $parents = array('selected_file_hasher');
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(
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)),
62 return parent::buildForm($form, $form_state);
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);
72 $values = $form_state->getValues();
74 $config = $this->config('hacked.settings');
75 $config->set('selected_file_hasher', $values['selected_file_hasher'])
78 parent::submitForm($form, $form_state);