class SettingsForm in Bootstrap Styles 1.0.x
Configure Bootstrap Styles settings.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, RedirectDestinationTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
- class \Drupal\bootstrap_styles\Form\SettingsForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of SettingsForm
1 string reference to 'SettingsForm'
File
- src/
Form/ SettingsForm.php, line 14
Namespace
Drupal\bootstrap_styles\FormView source
class SettingsForm extends ConfigFormBase {
/**
* The styles group plugin manager.
*
* @var \Drupal\bootstrap_styles\StylesGroup\StylesGroupManager
*/
protected $stylesGroupManager;
/**
* The styles plugin manager.
*
* @var \Drupal\bootstrap_styles\Style\StyleManager
*/
protected $styleManager;
/**
* Constructs a SettingsForm object.
*
* @param \Drupal\bootstrap_styles\StylesGroup\StylesGroupManager $styles_group_manager
* The styles group plugin manager.
* @param \Drupal\bootstrap_styles\Style\StyleManager $style_manager
* The styles plugin manager.
*/
public function __construct(StylesGroupManager $styles_group_manager, StyleManager $style_manager) {
$this->stylesGroupManager = $styles_group_manager;
$this->styleManager = $style_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('plugin.manager.bootstrap_styles_group'), $container
->get('plugin.manager.bootstrap_styles'));
}
/**
* Config settings.
*
* @var string
*/
const SETTINGS = 'bootstrap_styles.settings';
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'bootstrap_styles_admin_settings';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
static::SETTINGS,
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
$this
->messenger()
->addWarning('Important: the following classes are only used as an example to explain how to use this module. You should use your own theme classes.');
// Layout builder theme toggler.
$options = [
'dark' => $this
->t('Dark'),
'light' => $this
->t('Light'),
];
$form['layout_builder_theme'] = [
'#type' => 'select',
'#title' => $this
->t('Layout Builder Theme'),
'#options' => $options,
'#default_value' => $this
->config(static::SETTINGS)
->get('layout_builder_theme') ?? 'dark',
];
// Loop through styles groups plugins.
foreach ($this->stylesGroupManager
->getStylesGroups() as $group_plugin_id => $styles_group) {
// Style group form.
$group_instance = $this->stylesGroupManager
->createInstance($group_plugin_id);
$form = $group_instance
->buildConfigurationForm($form, $form_state);
if (isset($styles_group['styles'])) {
// Loop through styles plugins.
foreach (array_keys($styles_group['styles']) as $style_plugin_id) {
// Style plugin form.
$style_instance = $this->styleManager
->createInstance($style_plugin_id);
$form = $style_instance
->buildConfigurationForm($form, $form_state);
}
}
}
// Attach admin form style.
$form['#attached']['library'][] = 'bootstrap_styles/layout_builder_admin_form_style';
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
// Save layout builder theme.
$this
->config(static::SETTINGS)
->set('layout_builder_theme', $form_state
->getValue('layout_builder_theme'))
->save();
foreach ($this->stylesGroupManager
->getStylesGroups() as $group_plugin_id => $style_group) {
// Submit group form.
$group_instance = $this->stylesGroupManager
->createInstance($group_plugin_id);
$group_instance
->submitConfigurationForm($form, $form_state);
if (isset($style_group['styles'])) {
foreach ($style_group['styles'] as $style_plugin_id => $style) {
// Submit style form.
$style_instance = $this->styleManager
->createInstance($style_plugin_id);
$style_instance
->submitConfigurationForm($form, $form_state);
}
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 3 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 3 |
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. | |
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:: |
72 |
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. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
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. | |
SettingsForm:: |
protected | property | The styles plugin manager. | |
SettingsForm:: |
protected | property | The styles group plugin manager. | |
SettingsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
SettingsForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
SettingsForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
SettingsForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
SettingsForm:: |
constant | Config settings. | ||
SettingsForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
SettingsForm:: |
public | function |
Constructs a SettingsForm object. Overrides ConfigFormBase:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
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. |