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

ressa created an issue. See original summary.

silvi.addweb’s picture

Status: Active » Needs review

Thanks @ressa, I reviewed Both config (hoverintent_functionality and how_local_tasks), Then I
define type: boolean to admin_toolbar.schema.yml, as below

admin_toolbar.settings:
  type: config_object
  label: 'Admin Toolbar settings'
  mapping:
    menu_depth:
      type: integer
      label: 'Depth of displayed menu'
    toolbar_top:
      type: boolean
      label: 'Toolbar at top'

Now values in checkboxe is saved as true or false

drush cget admin_toolbar.settings
_core:
  default_config_hash: jvTSppzcgH5wnzBhX5xnAExcp2I1CzkQ_aky65XNfYI
menu_depth: 4
toolbar_top: true
cilefen’s picture

Status: Needs review » Active

There isn’t a merge request to review.

prashant.c’s picture

Status: Active » Closed (won't fix)

This issue is related to the contributed module https://www.drupal.org/project/admin_toolbar and not Drupal core, hence IMHO this could be closed.

ressa’s picture

Thank 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?