Problem/Motivation
When using the form element checkbox
, it is possible to disable the element but having its value remain checked. This is used, for example, on the module overview page, where it is possible to check more modules, but impossible to uncheck already enabled modules:
The same functionality is needed when using the form element "checkboxes
". Currently, when an option of the checkboxes is disabled, it is saved as unchecked, even when it was set as default value as checked
Steps to reproduce
Case 1
This case is covered by the test added in #7 and is fixed by the patch added in #26.
- Configure a block to be only visible on articles
- Add this hook to block.module
function block_form_block_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) { $form['visibility']['node_type']['bundles']['article']['#disabled'] = TRUE; }
- Go back to the block configuration form -- see that article is disabled but selected
- Save the block configuration again, without any changes
- Go back to the block configuration form -- see that article is disabled but NOT selected
Case 2
This case is not yet covered by tests and is not yet fixed.
- Add a field to article, as follows:
- Field type: boolean
- Field label: My Field
- Save and continue
- Set number of values to unlimited
- Save field settings
- Leave all settings, and click Save settings
- Configure the Manage form display
- to use the widget "Checkboxes/radio buttons".
- Add this line of code as the last line in
book_form_node_form_alter
$form['field_my_field']['widget'][0]['#disabled'] = TRUE;
- Enable the book module
- Add an article, view the form -- see that the first option is disabled but selected
- Submit the node form.
- Edit the new article node -- see that the first option is disabled but NOT selected
Proposed resolution
Ensure that disabled checkboxes values are not saved or their values persist.
Remaining tasks
- Manually test to confirm
- Write Tests to reproduce
- Fix bug
User interface changes
None
API changes
None
Data model changes
None