public function Toolbar::formFields in Simplifying 8
Get settings toolbar form fields.
File
- src/
Services/ Toolbar.php, line 76
Class
- Toolbar
- Class Toolbar.
Namespace
Drupal\simplifying\ServicesCode
public function formFields(&$form, $form_state) {
$form['toolbar_design_wrapper'] = [
'#type' => 'details',
'#title' => $this
->t('Toolbar design'),
'#group' => 'tabs',
];
$defs = $this->settingsactions
->getSettings('design');
$form['toolbar_design_wrapper']['small_button'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Small button'),
'#parents' => [
'design',
'small_button',
],
'#default_value' => !empty($defs['small_button']) ? 1 : 0,
];
$form['toolbar_design_wrapper']['top_background'] = [
'#type' => 'color',
'#title' => $this
->t('Top menu background'),
'#parents' => [
'design',
'top_background',
],
'#default_value' => !empty($defs['top_background']) ? $defs['top_background'] : '#3A9F00',
];
$form['toolbar_design_wrapper']['top_color'] = [
'#type' => 'color',
'#title' => $this
->t('Top menu color'),
'#parents' => [
'design',
'top_color',
],
'#default_value' => !empty($defs['top_color']) ? $defs['top_color'] : '#000000',
];
$form['toolbar_design_wrapper']['submenu_background'] = [
'#type' => 'color',
'#title' => $this
->t('Submenu background'),
'#parents' => [
'design',
'submenu_background',
],
'#default_value' => !empty($defs['submenu_background']) ? $defs['submenu_background'] : '#555555',
];
$form['toolbar_tabs_wrapper'] = [
'#type' => 'details',
'#title' => $this
->t('Toolbar tabs'),
'#group' => 'tabs',
];
$form['toolbar_tabs_wrapper']['toolbar_tabs'] = [
'#type' => 'checkboxes',
'#title' => $this
->t('Toolbar tabs'),
'#title_display' => 'invisible',
'#options' => $this
->getDefaultToolbarTabs(),
'#default_value' => $this
->getToolbarTabs(),
];
$menu_tree_parameters = new MenuTreeParameters();
$tree = $this->menutree
->load('admin', $menu_tree_parameters);
$manipulators = [
[
'callable' => 'menu.default_tree_manipulators:generateIndexAndSort',
],
];
$tree = $this->menutree
->transform($tree, $manipulators);
$options = [];
$tree_rout = '';
$this
->treeOptions($tree, $options, $tree_rout);
$defs = $this->settingsactions
->getSettings('menu_links');
$form['menu_links'] = [
'#type' => 'details',
'#title' => $this
->t('Menu links'),
'#group' => 'tabs',
];
$checkboxses = [];
foreach ($options as $key => $val) {
$disabled = in_array($val['path'], $checkboxses) ? TRUE : FALSE;
$checkboxses[] = $val['path'];
$form['menu_links'][$key] = [
'#prefix' => Markup::create('<div style="padding-left: ' . ($val['depth'] - 1) * 20 . 'px;">'),
'#suffix' => '</div>',
'#type' => 'checkbox',
'#parents' => [
'menu_links',
$val['path'],
],
'#title' => $val['title'],
'#disabled' => $disabled,
];
if (in_array($val['path'], $defs)) {
$form['menu_links'][$key]['#default_value'] = 1;
}
}
}