Problem/Motivation
I made a patch for Admin Toolbar today. But the custom form value was saved as 1, not true, which is what I wanted.
$form['toolbar_top'] = [
'#type' => 'checkbox',
'#title' => $this->t('Toolbar at top'),
'#description' => $this->t('Make toolbar stay at the top when scrolling.'),
'#default_value' => $config->get('toolbar_top'),
];
toolbar_top is the value I added:
$ drush config:get admin_toolbar.settings
_core:
default_config_hash: gxU5vT8-b1sXI8r3Ua2HCUdsEuVbvS7xjCXEqCqT6h8
menu_depth: 4
toolbar_top: 1
In another checkbox form the same module, values from checkboxes are saved as true or false (hoverintent_functionality and how_local_tasks):
$ drush config:get admin_toolbar_tools.settings
_core:
default_config_hash: WgdZsrd_5w9jlmcHV4R9dD2tG9OZEkYo4I_O8h7Gq8Q
max_bundle_number: 20
hoverintent_functionality: true
show_local_tasks: false
The issue: #3255672: Drupal admin_toolbar disable sticky/fixed state. Is there any option to do this?.
Steps to reproduce
Add a custom checkbox, and see that the value is saved as 1 or 0, true or false.
See also that another checkbox is saved as true or false.
Proposed resolution
Always save boolean values from custom checkboxes as true or false.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comments
Comment #2
silvi.addweb commentedThanks @ressa, I reviewed Both config (hoverintent_functionality and how_local_tasks), Then I
define type: boolean to admin_toolbar.schema.yml, as below
Now values in checkboxe is saved as true or false
Comment #3
cilefen commentedThere isn’t a merge request to review.
Comment #4
prashant.cThis issue is related to the contributed module https://www.drupal.org/project/admin_toolbar and not Drupal core, hence IMHO this could be closed.
Comment #5
ressaThank you everyone for fast replies, and resolving this issue so quickly. I agree, this should be fixed in the Admin Toolbar issue.
I wonder if it is documented somewhere on drupal.org that the correct method is to set custom checkbox to be a boolean in its schema?