drupalorg-1.0.x-dev/src/Form/DrupalOrgSettingsForm.php
src/Form/DrupalOrgSettingsForm.php
<?php
namespace Drupal\drupalorg\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Settings form for DrupalOrg GitLab integration.
*/
class DrupalOrgSettingsForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'drupalorg.settings',
];
}
/**
* {@inheritdoc}
*/
public function getFormId(): string {
return 'settings';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('drupalorg.settings');
$applied_config = \Drupal::config('drupalorg.settings');
if ($config->get('credit_migration_token') === 'CHANGE-ME') {
$this->messenger()->addError($this->t('Please change the default token for a valid one.'));
}
$form['credit_migration_token'] = [
'#type' => 'textfield',
'#title' => $this->t('Credit Migration Token'),
'#default_value' => $config->get('credit_migration_token'),
'#description' => $this->t('DrupalOrg Credit Migration token. Use this token to communicate between drupalorg-legacy (Drupal 7) instance and this instance to migrate credit information.'),
'#required' => TRUE,
];
$form['#theme'] = 'system_config_form';
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
if ($form_state->getValue('credit_migration_token') === 'CHANGE-ME') {
$form_state->setErrorByName('credit_migration_token', $this->t('Please change the default credit migration token for a valid one.'));
}
parent::validateForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$values = $form_state->getValues();
$this->config('drupalorg.settings')
->set('credit_migration_token', $values['credit_migration_token'])
->save();
}
}
