class BakerySettingsForm in Bakery Single Sign-On System 8.2
Configure bakery settings for this site.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
- class \Drupal\bakery\Forms\BakerySettingsForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of BakerySettingsForm
1 string reference to 'BakerySettingsForm'
File
- src/
Forms/ BakerySettingsForm.php, line 11
Namespace
Drupal\bakery\FormsView source
class BakerySettingsForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'bakery_admin_settings';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'bakery.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('bakery.settings');
$form['bakery_is_master'] = [
'#type' => 'checkbox',
'#title' => 'Is this the master site?',
'#default_value' => $config
->get('bakery_is_master'),
'#description' => $this
->t('On the master site, accounts need to be created by traditional processes, i.e by a user registering or an admin creating them.'),
];
$form['subsite_login'] = [
'#type' => 'radios',
'#title' => 'Subsite log in & registration',
'#options' => [
0 => $this
->t('Only log in & register on master site'),
1 => $this
->t('Allow log in & register on any site (deprecated)'),
],
'#default_value' => (int) $config
->get('subsite_login'),
'#description' => $this
->t('Limiting log ins and registration to the master site gives users a consistent experience and reduces the surface area available to attackers.'),
];
$form['bakery_master'] = [
'#type' => 'textfield',
'#title' => 'Master site',
'#default_value' => $config
->get('bakery_master'),
'#description' => $this
->t('Specify the master site for your bakery network.'),
];
$form['bakery_slaves'] = [
'#type' => 'textarea',
'#title' => 'Slave sites',
'#default_value' => implode("\n", $config
->get('bakery_slaves') ?: []),
'#description' => $this
->t('Specify any slave sites in your bakery network that you want to update if a user changes email or username on the master. Enter one site per line, in the form "http://sub.example.com/".'),
];
$form['bakery_help_text'] = [
'#type' => 'textarea',
'#title' => 'Help text for users with synch problems.',
'#default_value' => $config
->get('bakery_help_text'),
'#description' => $this
->t('This message will be shown to users if/when they have problems synching their accounts. It is an alternative to the "self repair" option and can be blank.'),
];
$form['bakery_freshness'] = [
'#type' => 'textfield',
'#title' => 'Seconds of age before a cookie is old',
'#default_value' => $config
->get('bakery_freshness'),
];
$form['bakery_key'] = [
'#type' => 'textfield',
'#title' => 'Private key for cookie validation',
'#default_value' => $config
->get('bakery_key'),
];
$form['bakery_domain'] = [
'#type' => 'textfield',
'#title' => 'Cookie domain',
'#default_value' => $config
->get('bakery_domain'),
];
$default = $config
->get('bakery_supported_fields');
$default['mail'] = 'mail';
$default['name'] = 'name';
$options = [
'name' => $this
->t('username'),
'mail' => $this
->t('e-mail'),
'status' => $this
->t('status'),
'picture' => $this
->t('user picture'),
'language' => $this
->t('language'),
'signature' => $this
->t('signature'),
];
// TODO: need to add profile fileds
/*
if (module_exists('profile')) {
$result = db_query('SELECT name, title FROM {profile_field}
ORDER BY category, weight');
foreach ($result as $field) {
$options[$field->name] = check_plain($field->title);
}
}
*/
$form['bakery_supported_fields'] = [
'#type' => 'checkboxes',
'#title' => 'Supported profile fields',
'#default_value' => $default,
'#options' => $options,
'#description' => $this
->t('Choose the profile fields that should be exported by the master and imported on the slaves. Username and E-mail are always exported. The correct export of individual fields may depend on the appropriate settings for other modules on both master and slaves. You need to configure this setting on both the master and the slaves.'),
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this
->config('bakery.settings');
$config
->set('bakery_is_master', $form_state
->getValue('bakery_is_master'))
->set('bakery_master', trim($form_state
->getValue('bakery_master'), '/') . '/')
->set('subsite_login', (bool) $form_state
->getValue('subsite_login'))
->set('bakery_help_text', $form_state
->getValue('bakery_help_text'))
->set('bakery_freshness', $form_state
->getValue('bakery_freshness'))
->set('bakery_key', $form_state
->getValue('bakery_key'))
->set('bakery_domain', $form_state
->getValue('bakery_domain'))
->set('bakery_supported_fields', $form_state
->getValue('bakery_supported_fields'));
if ($form_state
->getValue('bakery_slaves') && !empty($form_state
->getValue('bakery_slaves'))) {
// Transform the text string into an array.
$slaves = explode("\n", trim(str_replace("\r", '', $form_state
->getValue('bakery_slaves'))));
// For each entry, remove the trailing slash
// (if present) and concatenate with a new trailing slash.
foreach ($slaves as &$slave) {
$slave = trim($slave, '/') . '/';
}
$config
->set('bakery_slaves', $slaves);
}
else {
$config
->set('bakery_slaves', []);
}
$config
->save();
// Trigger some rebuilds that might be required by main/child changes.
\Drupal::service('router.builder')
->setRebuildNeeded();
parent::submitForm($form, $form_state);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BakerySettingsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
BakerySettingsForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
BakerySettingsForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
BakerySettingsForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
ConfigFormBase:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
13 |
ConfigFormBase:: |
public | function | Constructs a \Drupal\system\ConfigFormBase object. | 11 |
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |