When trying to save a FALSE-value in a boolean field, the Drupal\feeds\Feeds\Target\Boolean-class does not format it properly.

It sets the value in $values['value'] to be a boolean value, however, boolean fields in Drupal expect int (0/1). This results in a warning when importing entities, and the value is not saved:

SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: '' for column '[field_name]_value' at row 1: INSERT INTO {user__[field_name]} (entity_id, revision_id, bundle, delta, langcode, [field_name]_value) 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); Array ( [:db_insert_placeholder_0] => 10 [:db_insert_placeholder_1] => 10 [:db_insert_placeholder_2] => user [:db_insert_placeholder_3] => 0 [:db_insert_placeholder_4] => da [:db_insert_placeholder_5] => )

If i change the code to cast the boolean value to an integer, it works without warnings.

CommentFileSizeAuthor
#2 boolean_target_does_not-2769015-2.patch465 bytesmian3010

Comments

mian3010 created an issue. See original summary.

mian3010’s picture

StatusFileSize
new465 bytes

Attached proposed solution

twistor’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 2: boolean_target_does_not-2769015-2.patch, failed testing.

twistor’s picture

The BooleanTest needs to be updated.

+++ b/src/Feeds/Target/Boolean.php
@@ -21,7 +21,7 @@ class Boolean extends FieldTargetBase {
+    $values['value'] = (int) ((bool) trim((string) $values['value']));

We can remove the extra string cast. trim() will always return a string. Also, can remove the extra set of parenthesis.

  • twistor committed 4b2d16f on 8.x-3.x authored by mian3010
    Issue #2769015 by mian3010, twistor: Boolean target does not properly...
twistor’s picture

Status: Needs work » Fixed

Fixed on commit. As well as some other minor cleanups.

Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.