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

  1. Write a test to prove that this fails
  2. Decide a direction for the fix.
  3. Implement the fix

User interface changes

Depends on the implementation.

API changes

None

Data model changes

None

CommentFileSizeAuthor
1.png20.09 KBfomenkoandrey

Comments

fomenkoandrey created an issue. See original summary.

mathysp’s picture

Version: 8.1.0 » 8.4.x-dev
Component: base system » node system

We are having the same issue. It happens with both the "Promoted to front page" and the "Sticky on top of lists".

Steps to reproduce:

  1. Set up a new Drupal instance
  2. Edit the Content-type Article
  3. Set promotions options to yes for "promoted" and "sticky"
  4. Go to the form display
  5. Set widget to "Check boxes/radio buttons"
  6. Create a new node of type Article
  7. Set promotion or sticky to N/A
  8. Save the node

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

borisson_’s picture

Issue summary: View changes

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.

borisson_’s picture