Skip to content
Snippets Groups Projects

Issue #3491304: Clone field does not work

2 unresolved threads
1 file
+ 2
1
Compare changes
  • Side-by-side
  • Inline
@@ -93,7 +93,8 @@ public static function processEntityFieldSelect(&$element, FormStateInterface $f
$default_value = array_merge($default_value, $element['#default_value']);
}
$values += $default_value;
$values = isset($values) && is_array($values) ? $values : [];
$values = array_merge($values, $default_value);
    • Comment on lines -96 to +97

      $values += $default_value; gives an array that is different from the array returned from array_merge($values, $default_value);. It can be verified with the following code.

      $a1 = ["a" => 1, "b" => 2];
      $a2 = ["a" => 3, "c" => 4];
      $a1 = array_merge($a1, $a2);
      print_r($a1);
      
      $a1 = ["a" => 1, "b" => 2];
      $a2 = ["a" => 3, "c" => 4];
      $a1 += $a2;
      print_r($a1);
    • Comment on lines +96 to +97

      Furthermore, the error reported in the issue is Unsupported operand types: string + array, which means $values is a string. The code used in this merge request would use an empty array instead of a string, which probably would cause issues later.

Please register or sign in to reply
$element['#prefix'] = '<div id="' . EntityFieldSelect::getElementHTMLId($element, $complete_form) . '">';
$element['#suffix'] = '</div>';
if ($element['#title_display'] != 'invisible') {
Loading