Checkbox value is saved as 1, not false as desired

Created on 29 May 2024, 3 months ago
Updated 30 May 2024, 3 months ago

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: โœจ Drupal admin_toolbar disable sticky/fixed state. Is there any option to do this? Needs review .

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

๐Ÿ› Bug report
Status

Closed: won't fix

Version

10.3 โœจ

Component
Otherย  โ†’

Last updated about 8 hours ago

Created by

๐Ÿ‡ฉ๐Ÿ‡ฐDenmark ressa Copenhagen

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @ressa
  • Status changed to Needs review 3 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia dev16.addweb

    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
    
  • Status changed to Active 3 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States cilefen

    There isnโ€™t a merge request to review.

  • Status changed to Closed: won't fix 3 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Prashant.c Dharamshala

    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.

  • ๐Ÿ‡ฉ๐Ÿ‡ฐDenmark ressa Copenhagen

    Thank you everyone for fast replies, and resolving this issue so quickly. I agree, this should be fixed in the Admin Toolbar issue.

Production build 0.71.5 2024