devel_wizard-2.x-dev/src/Config/SettingsForm.php
src/Config/SettingsForm.php
<?php
declare(strict_types=1);
namespace Drupal\devel_wizard\Config;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
class SettingsForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'devel_wizard_settings_form';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'devel_wizard.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$settings = $this->config('devel_wizard.settings');
$form['php'] = [
'#type' => 'details',
'#tree' => TRUE,
'#title' => $this->t('PHP'),
'#open' => TRUE,
'bin_dir' => [
'#type' => 'textfield',
'#title' => $this->t('Directory contains the php executable'),
'#default_value' => $settings->get('php.bin_dir'),
],
'php_executable' => [
'#type' => 'textfield',
'#title' => $this->t('PHP executable'),
'#default_value' => $settings->get('php.php_executable'),
],
];
$form['composer'] = [
'#type' => 'details',
'#tree' => TRUE,
'#title' => $this->t('Composer'),
'#open' => TRUE,
'composer_executable' => [
'#type' => 'textfield',
'#required' => TRUE,
'#title' => $this->t('Composer executable'),
'#default_value' => $settings->get('composer.composer_executable'),
],
];
$form['git'] = [
'#type' => 'details',
'#tree' => TRUE,
'#title' => $this->t('Git'),
'#open' => TRUE,
'git_executable' => [
'#type' => 'textfield',
'#required' => TRUE,
'#title' => $this->t('Git executable'),
'#default_value' => $settings->get('git.git_executable'),
],
];
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state->getValues();
$settings = $this->config('devel_wizard.settings');
$settings
->set('php', $values['php'])
->set('composer', $values['composer'])
->set('git', $values['git'])
->save();
parent::submitForm($form, $form_state);
}
}
