When using the select list widget type for fields such as taxonomies, the following error is encountered:

Fatal error: [] operator not supported for strings in /var/www/*/sites/all/modules/contrib/prepopulate/src/Controller/prepopulateController.php on line 51

In Drupal 8, the select list field may be populated with merely the following URL argument: node/add/content_type?edit[field_name]=92

As opposed to the method given in the documentation for Drupal 7 which is as follows:

Taxonomy fields with widget type select list and term ID:
http://www.example.com/node/add/node?edit[field_ch_projekt_2][und]=92

As we no longer pass the [und] along to the prepopulate module, it is unnecessary to pass an empty array key on line 51 of prepopulateController.php

So we change line 51 from this: $form['widget']['#value'][] = $request_slice;

To simply this: $form['widget']['#value'] = $request_slice;

I have tested the patch and it has resolved the issue for me.

CommentFileSizeAuthor
#2 fixing-select-list-2712529-1.patch530 bytesrich_dawson

Comments

rich_dawson created an issue. See original summary.

rich_dawson’s picture

StatusFileSize
new530 bytes
rich_dawson’s picture

Status: Needs work » Needs review
walkingdexter’s picture

Good patch, works for me.

juliencarnot’s picture

Status: Needs review » Reviewed & tested by the community

Fix tested by WalkingDexter, MrVee on related issue, and me...

  • jbrauer committed 7a9da4f on 8.x-2.x
    Issue #2712529 by rich_dawson: Fatal error: [] operator not supported...
jbrauer’s picture

Status: Reviewed & tested by the community » Fixed

Committed. Thanks.

Status: Fixed » Closed (fixed)

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