I'm using this module with drupal 8.2. I have a entity reference field to the taxonomy term of some vocabulary. User could select only one term as a value of this field. During save there is an error in apache log:

[Thu Nov 24 16:56:02.563853 2016] [:error] [pid 33800] [client 109.228.63.58:56009] PHP Fatal error: Cannot create references to/from string offsets nor overloaded objects in /var/www/drupal/core/lib/Drupal/Component/Utility/NestedArray.php on line 158, referer: ...

I have investigated this and noticed that everything is working fine when more than one value is allowed for this field. $form_state->setValueForElement() is called with:

$value = array (
  0 => array (
    'target_id' => array (
      0 =>array (
        48 => NULL,
      ),
    ),
  ),
)

when it's not working and with:

$value = array (
  0 => array (
    'target_id' => '48',
  ),
);

when it's working. So there is few, unnecessary levels of nesting in that array, and index is replaced with value.

Let me know if you need more information.

And, last but not leasy - thanks for the module! :)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

wikp created an issue. See original summary.

wikp’s picture

Issue summary: View changes
alex_optim’s picture

Check please my patch.

alex_optim’s picture

Status: Active » Needs review
yogeshmpawar’s picture

Assigned: Unassigned » yogeshmpawar
navneet0693’s picture

Assigned: yogeshmpawar » Unassigned

Unassigning citing no activity.

alex_optim’s picture

I was mistaken with my previous patch, so I have created a new one.

yogeshmpawar’s picture

Status: Needs review » Needs work

@alex_optim - Still same error.

alex_optim’s picture

Assigned: Unassigned » alex_optim
alex_optim’s picture

Assigned: alex_optim » Unassigned
millenc’s picture

Thus bug algo happens on the 8.x-1.0-alpha2 version and I can confirm that the suggested patches don't work. Added a related issue. Any ideas on how to fix this? (it's the only thing stopping me from using this module)

pallavi_sugandhi’s picture

Same issue not able to save the node with taxonomy reference tree widgets.

alex_optim’s picture

Status: Needs work » Needs review
FileSize
955 bytes
stefank’s picture

Status: Needs review » Reviewed & tested by the community

@alex_optim thanks for the patch in #13. I have tested the patch and it seems to be working. The cardinality of the field is set to 1 and using radio buttons. Works even when there are multiple Taxonomy Term Reference Tree on the same form.

fonant’s picture

Patch in #13 fixes errors when using single-item field for me. Thanks!

stopopol’s picture

I can confirm that #13 works
Please commit this patch for the next release.

  • alex_optim committed 69190a8 on 8.x-1.x
    Issue #2830378 by alex_optim: Validation broken with radios
    
alex_optim’s picture

Status: Reviewed & tested by the community » Patch (to be ported)
alex_optim’s picture

Status: Patch (to be ported) » Fixed
alex_optim’s picture

Status: Fixed » Closed (fixed)