class ModuleSettingsForm in Layout Builder Styles 8
Class ModuleSettingsForm.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\layout_builder_styles\Form\ModuleSettingsForm
Expanded class hierarchy of ModuleSettingsForm
1 string reference to 'ModuleSettingsForm'
File
- src/
Form/ ModuleSettingsForm.php, line 13
Namespace
Drupal\layout_builder_styles\FormView source
class ModuleSettingsForm extends FormBase {
/**
* Drupal\Core\Config\ConfigManager definition.
*
* @var \Drupal\Core\Config\ConfigManager
*/
protected $configManager;
/**
* Constructs a new RestrictionPluginConfigForm object.
*/
public function __construct(ConfigManager $config_manager) {
$this->configManager = $config_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config.manager'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'layout_builder_styles_config_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->configFactory()
->get('layout_builder_styles.settings');
$form['multiselect'] = [
'#type' => 'radios',
'#title' => $this
->t('Multiple styles'),
'#default_value' => $config
->get('multiselect'),
'#options' => [
'single' => $this
->t('Limit one style per given section or block.'),
'multiple' => $this
->t('Allow multiple styles to be selected on a given section or block.'),
],
'#description' => $this
->t('Limiting to one style per section or block is useful for sites which need each style choice to dictate the markup of the template. When this option is chosen, a corresponding block theme hook suggestion is provided. Allowing multiple styles is useful for sites whose style declarations correspond wholly to CSS modifications, and whose styles are designed to be used in conjunction. <strong>Note</strong>: if you switch this setting from "multiple" to "single" after Layout Builder Styles is already in use, any blocks that had been assigned multiple styles will initially continue to render with multiple styles until the block form is revisted; at that point, the Layout Builder Style options will be reset to no selections, and content editors should take care to reapply the single style they want to use.'),
];
$form['form_type'] = [
'#type' => 'radios',
'#title' => $this
->t('Form element for multiple styles'),
'#default_value' => $config
->get('form_type'),
'#options' => [
'checkboxes' => $this
->t('Checkboxes'),
'multiple-select' => $this
->t('Select (multiple) box'),
],
'#description' => $this
->t('Choose whether the styles selector should display as multiple checkboxes or a select (multiple) box.'),
'#states' => [
'visible' => [
':input[name="multiselect"]' => [
'value' => 'multiple',
],
],
],
];
$form['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Save configuration'),
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$multiselect = $form_state
->getValue('multiselect');
$form_type = $form_state
->getValue('form_type');
$config = $this
->configFactory()
->getEditable('layout_builder_styles.settings');
$config
->set('multiselect', $multiselect);
$config
->set('form_type', $form_type);
$config
->save();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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 | Retrieves a configuration object. | |
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. | |
ModuleSettingsForm:: |
protected | property | Drupal\Core\Config\ConfigManager definition. | |
ModuleSettingsForm:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
ModuleSettingsForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
ModuleSettingsForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
ModuleSettingsForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
ModuleSettingsForm:: |
public | function | Constructs a new RestrictionPluginConfigForm object. | |
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. |