class FasttoggleSettingsForm in Fasttoggle 8.2
Same name and namespace in other branches
- 8.3 src/Form/FasttoggleSettingsForm.php \Drupal\fasttoggle\Form\FasttoggleSettingsForm
Configure fasttoggle 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\fasttoggle\Form\FasttoggleSettingsForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of FasttoggleSettingsForm
1 string reference to 'FasttoggleSettingsForm'
File
- src/
Form/ FasttoggleSettingsForm.php, line 20 - Contains \Drupal\fasttoggle\Form\FasttoggleSettingsForm.
Namespace
Drupal\fasttoggle\FormView source
class FasttoggleSettingsForm extends ConfigFormBase {
/**
* @var \Drupal\fasttoggle\Controller\FasttoggleController
* The Fasttoggle controller.
*/
private $controller;
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'fasttoggle.settings';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$this->controller = new \Drupal\fasttoggle\Controller\FasttoggleController();
$this->objectManager = \Drupal::service('plugin.manager.fasttoggle.setting_object');
$this->groupManager = \Drupal::service('plugin.manager.fasttoggle.setting_group');
$this->settingManager = \Drupal::service('plugin.manager.fasttoggle.setting');
$this->contextManager = \Drupal::service('plugin.manager.fasttoggle.context');
return self::buildFormContent($form, $form_state);
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
static $result = NULL;
if (is_null($result)) {
$settings = $this->settingManager
->getDefinitions();
$result = [];
foreach ($settings as $object_type => $groups) {
foreach ($groups as $group_name => $settings) {
$result = array_merge($result, array_keys($settings));
}
}
}
return $result;
}
/**
* Get the sitewide settings form content.
*
* @param array $form
* The Drupal form array.
* @param array $form_state
* The Drupal form_state array.
*/
public function buildFormContent(array $form, FormStateInterface $form_state) {
$config = $this
->config('fasttoggle.settings');
$form['label_style'] = [
'#type' => 'radios',
'#title' => t('Label style'),
'#description' => t('Select what kind of labels you want for fasttoggle links. See the README.txt for information about providing your own labels.'),
'#options' => [
FASTTOGGLE_LABEL_STATUS => t('Status (reflects the current state, e.g. "published", "active")'),
FASTTOGGLE_LABEL_ACTION => t('Action (shows what happens upon a click, e.g. "unpublish", "block")'),
],
'#default_value' => $config
->get('label_style'),
];
if (0) {
// @TODO Custom labels.
$custom_labels = $config
->get('custom_labels');
if (!empty($custom_labels)) {
$form['fasttoggle_label_style']['#options'][FASTTOGGLE_LABEL_CUSTOM] = t('Custom (configure in your settings.php)');
}
}
// Get all settings, grouped by entity and setting group.
$objects = $this->objectManager
->getDefinitions();
$groups = $this->groupManager
->getDefinitions();
$settings = $this->settingManager
->getDefinitions();
foreach ($objects as $object => $objectDef) {
$object_plugin = $this->objectManager
->createInstance($object);
$elements_for_type = $object_plugin
->getSitewideSettingFormElements($config);
foreach ($groups[$object] as $group => $groupDef) {
$groupPlugin = $this->groupManager
->createInstance($group);
foreach ($settings[$object][$group] as $setting => $settingDef) {
if (!isset($elements_for_type[$group])) {
if ($groupDef['title']) {
$elements_for_type[$group] = [
'#type' => 'fieldset',
'#title' => $groupDef['title'],
'#description' => $groupDef['description'],
'#weight' => $groupDef['weight'],
];
$fieldset =& $elements_for_type[$group];
}
else {
$fieldset =& $elements_for_type;
}
}
$setting_plugin = $this->settingManager
->createInstance($setting);
$configKeys = $setting_plugin
->configSettingKeys();
foreach ($configKeys as $key) {
$fieldset[$key] = $setting_plugin
->settingForm($config, $key);
}
}
}
if (!empty($elements_for_type)) {
$form[$object] = [
'#type' => 'fieldset',
'#title' => $objectDef['title'],
'#description' => $objectDef['description'],
'#weight' => $objectDef['weight'],
];
$form[$object] += $elements_for_type;
}
}
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this
->config('fasttoggle.settings');
$configKeys = [];
$settings_obj = $this
->configFactory()
->getEditable('fasttoggle.settings');
$settings_obj
->set('label_style', $form_state
->getValue('label_style'));
$objects = $this->objectManager
->getDefinitions();
$group = $this->groupManager
->getDefinitions();
$object_settings = $this->settingManager
->getDefinitions();
foreach ($object_settings as $type => $groups) {
$plugin = $this->objectManager
->createInstance($type);
$configKeys += array_keys($plugin
->getSitewideSettingFormElements($config));
foreach ($groups as $group => $settings) {
$plugin = $this->groupManager
->createInstance($group);
$configKeys += array_keys($plugin
->getSitewideSettingFormElements($config));
foreach ($settings as $setting => $settingDef) {
$plugin = $this->settingManager
->createInstance($setting);
$configKeys += array_merge($configKeys, $plugin
->getSitewideSettingFormElements($config));
$configKeys += array_merge($configKeys, $plugin
->configSettingKeys());
}
}
}
foreach ($configKeys as $key) {
$new_value = $form_state
->getValue($key);
$settings_obj
->set($key, $new_value)
->save();
}
parent::submitForm($form, $form_state);
}
/**
*
*/
public function systemAdminMenuFasttogglePage() {
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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 | |
FasttoggleSettingsForm:: |
private | property | The Fasttoggle controller. | |
FasttoggleSettingsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
FasttoggleSettingsForm:: |
public | function | Get the sitewide settings form content. | |
FasttoggleSettingsForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
FasttoggleSettingsForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
FasttoggleSettingsForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
FasttoggleSettingsForm:: |
public | function | ||
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. |