HackedSettingsForm.php in Hacked! 8.2
File
src/Form/HackedSettingsForm.php
View source
<?php
namespace Drupal\hacked\Form;
use Drupal\Component\Utility\Html;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
class HackedSettingsForm extends ConfigFormBase {
protected function getEditableConfigNames() {
return [
'hacked.settings',
];
}
public function getFormID() {
return 'hacked_settings';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('hacked.settings');
$hashers = hacked_get_file_hashers();
$form['selected_file_hasher'] = array(
'#type' => 'details',
'#title' => t('File hasher'),
'#open' => TRUE,
);
$parents = array(
'selected_file_hasher',
);
foreach ($hashers as $name => $hasher_info) {
$parents_for_id = array_merge($parents, array(
$name,
));
$form['selected_file_hasher'][$name] = array(
'#type' => 'radio',
'#title' => $hasher_info['name'],
'#default_value' => $config
->get('selected_file_hasher'),
'#return_value' => $name,
'#parents' => $parents,
'#description' => !empty($hasher_info['description']) ? $hasher_info['description'] : '',
'#id' => Html::getId('edit-' . implode('-', $parents_for_id)),
);
}
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValues();
$config = $this
->config('hacked.settings');
$config
->set('selected_file_hasher', $values['selected_file_hasher'])
->save();
parent::submitForm($form, $form_state);
}
}