Problem/Motivation
Saving a node with no value for sticky/promotion leads to a fatal error.
[29-Apr-2016 20:28:15 Europe/Kiev] Uncaught PHP Exception Drupal\Core\Entity\EntityStorageException: "SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'promote' cannot be null: INSERT INTO {node_field_data} (nid, vid, type, langcode, title, uid, status, created, changed, promote, sticky, revision_translation_affected, default_langcode) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11, :db_insert_placeholder_12); Array
(
[:db_insert_placeholder_0] => 91
[:db_insert_placeholder_1] => 91
[:db_insert_placeholder_2] => article
[:db_insert_placeholder_3] => ru
[:db_insert_placeholder_4] => [ОТМЕНЕНО] Фестиваль Рок посиделки «Бабье лето» 2016
[:db_insert_placeholder_5] => 69
[:db_insert_placeholder_6] => 1
[:db_insert_placeholder_7] => 1450940817
[:db_insert_placeholder_8] => 1461950895
[:db_insert_placeholder_9] =>
[:db_insert_placeholder_10] => 0
[:db_insert_placeholder_11] => 1
[:db_insert_placeholder_12] => 1
)
" at /.../core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php line 756
This only happens if the stick/promoted form display is set to radios widget.
Proposed resolution
A couple of options spring to mind:
- Add extra validation to make sure that there's always a value for those checkboxes (or other basefields, I think this will happen for all boolean base fields)
- Make sure boolean base fields have to be required when they use the radios widget.
- Disable radios widget for boolean base fields.
- Another option?
Remaining tasks
- Write a test to prove that this fails
- Decide a direction for the fix.
- Implement the fix
User interface changes
Depends on the implementation.
API changes
None
Data model changes
None
| Comment | File | Size | Author |
|---|---|---|---|
| 1.png | 20.09 KB | fomenkoandrey |
Comments
Comment #2
mathysp commentedWe are having the same issue. It happens with both the "Promoted to front page" and the "Sticky on top of lists".
Steps to reproduce:
If instead of "Check boxes/radio buttons"-widtget you use "Single on/off checkbox" then this behavior does not happen.
So this seems to be an edge case only for the "Check boxes/radio buttons"-widtget
Comment #3
borisson_Updated the IS.
It seems real easy to write a test based on the description in #2. I'll try to give that a go after work today if noone beats me to it.
Comment #4
borisson_I brought this up to swentel and he mentioned that #2306331: "Single on/off checkbox" widget makes no sense for boolean fields with cardinality > 1 and "Check boxes/radio buttons" makes little sense for boolean fields with cardinality > 2 is the issue here. Closing this.