SettingsForm.php in Build Hooks 8.2
File
modules/build_hooks_bitbucket/src/Form/SettingsForm.php
View source
<?php
namespace Drupal\build_hooks_bitbucket\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class SettingsForm extends ConfigFormBase {
protected $manager;
public static function create(ContainerInterface $container) {
$static = parent::create($container);
$static->manager = $container
->get('build_hooks_bitbucket.bitbucket_manager');
return $static;
}
public function getFormId() {
return 'build_hooks_bitbucket_settings';
}
protected function getEditableConfigNames() {
return [
'build_hooks_bitbucket.settings',
];
}
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('build_hooks_bitbucket.settings');
$form['username'] = [
'#type' => 'textfield',
'#title' => $this
->t('Username'),
'#default_value' => $config
->get('username'),
];
$form['password'] = [
'#type' => 'password',
'#title' => $this
->t('App Password'),
];
if (!empty($config
->get('password'))) {
$form['password']['#description'] = $this
->t('Password set. Leave blank to keep current password.');
}
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this
->config('build_hooks_bitbucket.settings');
$config
->set('username', $form_state
->getValue('username'));
if (!empty($form_state
->get('password'))) {
$config
->set('password', $form_state
->getValue('password'));
}
$config
->save();
parent::submitForm($form, $form_state);
}
}
Classes
Name |
Description |
SettingsForm |
Configure build_hooks_bitbucket settings for this site. |