View source
<?php
namespace Drupal\shib_auth\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
class ShibbolethSettings extends ConfigFormBase {
protected function getEditableConfigNames() {
return [
'shib_auth.shibbolethsettings',
];
}
public function getFormId() {
return 'shibboleth_settings';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('shib_auth.shibbolethsettings');
$form['shibboleth_handler_settings'] = [
'#type' => 'details',
'#title' => $this
->t('Shibboleth Handler Settings'),
'#open' => 'open',
];
$form['shibboleth_handler_settings']['shibboleth_login_handler_url'] = [
'#type' => 'textfield',
'#title' => $this
->t('Shibboleth login handler URL'),
'#description' => $this
->t('The URL can be absolute or relative to the server base url: http://www.example.com/Shibboleth.sso/DS; /Shibboleth.sso/DS'),
'#maxlength' => 128,
'#size' => 64,
'#default_value' => $config
->get('shibboleth_login_handler_url'),
];
$form['shibboleth_handler_settings']['shibboleth_logout_handler_url'] = [
'#type' => 'textfield',
'#title' => $this
->t('Shibboleth logout handler URL'),
'#description' => $this
->t('The URL can be absolute or relative to the server base url: http://www.example.com/Shibboleth.sso/Logout; /Shibboleth.sso/Logout'),
'#maxlength' => 128,
'#size' => 64,
'#default_value' => $config
->get('shibboleth_logout_handler_url'),
];
$form['shibboleth_handler_settings']['shibboleth_login_link_text'] = [
'#type' => 'textfield',
'#title' => $this
->t('Shibboleth login link text'),
'#description' => $this
->t('The text of the login link. You can change this text on the Shibboleth login block settings form too!'),
'#maxlength' => 128,
'#size' => 64,
'#default_value' => $config
->get('shibboleth_login_link_text'),
];
$form['shibboleth_handler_settings']['force_https_on_login'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Force HTTPS on login'),
'#description' => $this
->t('The user will be redirected to HTTPS'),
'#default_value' => $config
->get('force_https_on_login'),
];
$form['attribute_settings'] = [
'#type' => 'details',
'#title' => $this
->t('Attribute Settings'),
'#open' => 'open',
];
$form['attribute_settings']['server_variable_username'] = [
'#type' => 'textfield',
'#title' => $this
->t('Server variable for username'),
'#maxlength' => 128,
'#size' => 64,
'#default_value' => $config
->get('server_variable_username'),
];
$form['attribute_settings']['server_variable_email'] = [
'#type' => 'textfield',
'#title' => $this
->t('Server variable for e-mail address'),
'#maxlength' => 128,
'#size' => 64,
'#default_value' => $config
->get('server_variable_email'),
];
$form['debugging_options'] = [
'#type' => 'details',
'#title' => $this
->t('Debugging Options'),
'#open' => 'open',
];
$form['debugging_options']['enable_debug_mode'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable DEBUG mode.'),
'#default_value' => $config
->get('enable_debug_mode'),
];
$form['debugging_options']['debug_prefix_path'] = [
'#type' => 'textfield',
'#title' => $this
->t('DEBUG path prefix'),
'#description' => $this
->t("For example, use \"/user/\" to display DEBUG messages on paths like \"/user/*\"."),
'#maxlength' => 128,
'#size' => 64,
'#default_value' => $config
->get('debug_prefix_path'),
];
return parent::buildForm($form, $form_state);
}
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$this
->config('shib_auth.shibbolethsettings')
->set('shibboleth_login_handler_url', $form_state
->getValue('shibboleth_login_handler_url'))
->set('shibboleth_logout_handler_url', $form_state
->getValue('shibboleth_logout_handler_url'))
->set('shibboleth_login_link_text', $form_state
->getValue('shibboleth_login_link_text'))
->set('force_https_on_login', $form_state
->getValue('force_https_on_login'))
->set('server_variable_username', $form_state
->getValue('server_variable_username'))
->set('server_variable_email', $form_state
->getValue('server_variable_email'))
->set('enable_debug_mode', $form_state
->getValue('enable_debug_mode'))
->set('debug_prefix_path', $form_state
->getValue('debug_prefix_path'))
->save();
\Drupal::service('cache_tags.invalidator')
->invalidateTags([
'shibboleth_login_block',
]);
}
}