-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfirmOptionsForm.php
119 lines (104 loc) · 3.5 KB
/
ConfirmOptionsForm.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
namespace Drupal\drupal10_custom_module\Form;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Menu\MenuLinkManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Settings form for example_module Tools.
*
* @package Drupal\example_module\Form
*/
class ConfirmOptionsForm extends ConfigFormBase {
/**
* The cache menu instance.
*
* @var \Drupal\Core\Cache\CacheBackendInterface
*/
protected $cacheMenu;
/**
* The menu link manager instance.
*
* @var \Drupal\Core\Menu\MenuLinkManagerInterface
*/
protected $menuLinkManager;
/**
* AdminToolbarToolsSettingsForm constructor.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
* The factory for configuration objects.
* @param \Drupal\Core\Menu\MenuLinkManagerInterface $menuLinkManager
* A menu link manager instance.
* @param \Drupal\Core\Cache\CacheBackendInterface $cacheMenu
* A cache menu instance.
*/
public function __construct(ConfigFactoryInterface $configFactory, MenuLinkManagerInterface $menuLinkManager, CacheBackendInterface $cacheMenu) {
parent::__construct($configFactory);
$this->cacheMenu = $cacheMenu;
$this->menuLinkManager = $menuLinkManager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory'),
$container->get('plugin.manager.menu.link'),
$container->get('cache.menu')
);
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'admin_toolbar_tools.settings',
];
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'admin_toolbar_tools_settings';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('admin_toolbar_tools.settings');
$form['max_bundle_number'] = [
'#type' => 'number',
'#title' => $this->t('Maximum number of bundle sub-menus to display'),
'#description' => $this->t('Loading a large number of items can cause performance issues.'),
'#default_value' => $config->get('max_bundle_number'),
];
$form['hoverintent_functionality'] = [
'#type' => 'checkbox',
'#title' => $this->t('Enable/Disable the hoverintent functionality'),
'#description' => $this->t('Check it if you want to enable the hoverintent feature.'),
'#default_value' => $config->get('hoverintent_functionality'),
];
$form['show_local_tasks'] = [
'#type' => 'checkbox',
'#title' => $this->t('Enable/Disable local tasks display'),
'#description' => $this->t('Local tasks such as node edit and delete.'),
'#default_value' => $config->get('show_local_tasks'),
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->config('admin_toolbar_tools.settings')
->set('max_bundle_number', $form_state->getValue('max_bundle_number'))
->set('hoverintent_functionality', $form_state->getValue('hoverintent_functionality'))
->set('show_local_tasks', $form_state->getValue('show_local_tasks'))
->save();
parent::submitForm($form, $form_state);
$this->cacheMenu->invalidateAll();
$this->menuLinkManager->rebuild();
}
}