Warning: array_flip(): Can only flip STRING and INTEGER values! in Drupal\Core\Entity\FieldableDatabaseStorageController->loadMultiple() (line 149 of core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php).

at

admin/structure/types/manage/article/fields

After a fresh D8 install, go at

admin/structure/types/manage/article/fields/node.article.field_tags

edit the label and save it.

I've found it using PHP 5.3.10, but it was also reported happening with PHP 5.5.9.

Comments

rodrigo panchiniak fernandes’s picture

Status: Active » Needs review
StatusFileSize
new17.65 KB

This patch solves the issue avoiding arrays with an empty value. Not sure if it was correctly generated. This is my first patch submission. :)

revagomes’s picture

+++ b/core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php
@@ -181,15 +193,16 @@ public function loadMultiple(array $ids = NULL) {
+      If ($passed_ids) {

This If must be lowercase.

Status: Needs review » Needs work

The last submitted patch, 1: add_condition_for_array_flip-2193237-1.patch, failed testing.

revagomes’s picture

StatusFileSize
new2.26 KB

Helping Panchiniak with his first patch ;)

Rerolling against HEAD.

rodrigo panchiniak fernandes’s picture

Status: Needs work » Needs review

#1 was generated over the wrong file. #4 is ready for review. Thank you @revagomes.

stefan lehmann’s picture

Issue tags: +Novice
amateescu’s picture

Component: configuration entity system » entity system
Status: Needs review » Postponed (maintainer needs more info)

I cannot reproduce this bug on a fresh standard D8 install. Can you please provide more steps to reproduce?

rodrigo panchiniak fernandes’s picture

Issue summary: View changes
Status: Postponed (maintainer needs more info) » Needs review
stefan lehmann’s picture

I verify, that the notice appeared and that the Patch fixes this.

I found however, that a FATAL error appears, if you enter a default value and press Save, but this seems to be unrelated to this issue, as it also happens without applying the patch above.

Created a bug report for the issue mentioned above here: https://drupal.org/node/2195973

(Done during the Drupal South 2014 Code Sprint in Wellington)

rodrigo panchiniak fernandes’s picture

Thank you for the comment and additional error report. I've found the crash with default term only happens when it is chosen a value that is not yet a term of the vocabulary (tags). I personally don't like the behaviour of creating a new content from auto complete fields. Mostly because, in this scenario, setting a field should not correspond to adding a content (considering taxonomy term as a content). So, the option of adding a Default term should be restricted only for non empty vocabularies, and, in my opinion, the auto complete should force on already available options. But, as you said, this is not related to the current issue. Other option would be dealing with default values only (or mostly) at the front end, with no previous filling of the taxonomy itself, until a real content is added.

barraponto’s picture

I followed the traceback to TaxonomyAutocompleteWidget and fixed it there.
But I wonder if $items shouldn't just be empty (and skip the whole foreach loop).

amateescu’s picture

StatusFileSize
new1.01 KB

I think a better fix would be to check if $items is not empty before trying to compute the default value for the form element, just like Entity reference does.

amateescu’s picture

Component: entity system » taxonomy.module
Issue tags: +Entity Field API
barraponto’s picture

Status: Needs review » Reviewed & tested by the community

Tested, it works fine.

revagomes’s picture

I've tested the #12 also and it's OK.

I was thinking about the solution we have right now and I'm not sure about this anymore.

Taking in count that the system has to have a tid in order to store the default value the best thing to do would be warn the user about the creation of the default term.

Earlier I was thinking to approach this with a checkbox to allow the user to decide if he/she wants to create the default value if it doesn't already exists but now I realized that maybe the best solution is to be verbose and let the user to know how the system works. I'm not sure if the creation of the default term outside of the "admin/structure/taxonomy/manage/[vocabulary]/add" page makes sense for everyone but thats the way the system works. So the end user has to be aware.

What do you guys think about this?

revagomes’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs work

I've tested again trying to set 2 tags as the default value for the articles and I've got another error:

Fatal error: Call to a member function uuid() on a non-object in /[...]/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Field/FieldType/TaxonomyTermReferenceFieldItemList.php on line 74

After that I clicked Back in the browser and I had the same error about the array_flip() plus a notice:

Warning: array_flip(): Can only flip STRING and INTEGER values! in Drupal\Core\Entity\FieldableDatabaseStorageController->loadMultiple() (line 147 of core/lib/Drupal/Core/Entity/FieldableDatabaseStorageController.php).

Notice: Undefined index: in Drupal\taxonomy\Plugin\Field\FieldType\TaxonomyTermReferenceFieldItemList->defaultValuesFormSubmit() (line 74 of core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Field/FieldType/TaxonomyTermReferenceFieldItemList.php).

I'm moving the status back to Needs work.

barraponto’s picture

Status: Needs work » Reviewed & tested by the community

@revagomes there's another issue for that: #2195973: Setting default value on Article->Tags field leads to FATAL error..
This issue is RTBC already.

catch’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

Looks like we could add test coverage for this. Patch itself looks fine though.

barraponto’s picture

@catch can't the test come from #2195973: Setting default value on Article->Tags field leads to FATAL error.? This is just a trivial fix, the other issue is the heavy thing.

rodrigo panchiniak fernandes’s picture

Thank you for the review, @catch. Nevertheless the comment of @barraponto, considering this is a PHP bug fix, it should be accompanied by a test according to Core Gates. I will try to follow this guide for providing it.

czigor’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new2.58 KB

Added a test case to check if no PHP error is present on the field instance settings page for autocomplete widget.

czigor’s picture

Adding a missing newline.

czigor’s picture

This patch contains only the test (and not the fix) so it should fail.

Status: Needs review » Needs work

The last submitted patch, 23: core-taxonomy_autocomplete_warning-2193237-23.patch, failed testing.

czigor’s picture

The last submitted patch, 22: core-taxonomy_autocomplete_warning-2193237-22.patch, failed testing.

czigor’s picture

czigor’s picture

Status: Needs work » Needs review
janoka’s picture

StatusFileSize
new9.38 KB
new3.87 KB

I checked the page before applying the patch and after it.
Please see the screenshots.

Before:

After:

shkodrava’s picture

Patch #22 worked for me.

shkodrava’s picture

Status: Needs review » Reviewed & tested by the community
alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed a6658cd and pushed to 8.x. Thanks!

  • Commit a6658cd on 8.x by alexpott:
    Issue #2193237 by czigor, amateescu, barraponto, revagomes, rodrigo...

Status: Fixed » Closed (fixed)

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

Status: Closed (fixed) » Needs work

The last submitted patch, 23: core-taxonomy_autocomplete_warning-2193237-23.patch, failed testing.

berdir’s picture

Status: Needs work » Closed (fixed)