// Allow for elements to expand to multiple elements, e.g., radios,
  // checkboxes and files.
  if (isset($element['#process']) && !$element['#processed']) {
    foreach ($element['#process'] as $process) {
      $element = call_user_func_array($process, array(&$element, &$form_state, &$form_state['complete_form']));
    }
    $element['#processed'] = TRUE;
  }

$element is about to get overwritten with the return value from the callback. So there's no point in passing it by reference surely?

Comments

joachim’s picture

Status: Active » Needs review
Issue tags: +Quick fix
StatusFileSize
new646 bytes

Here's a patch.

Doesn't need a backport to D7.

Knock-on effect of this is a reroll of docs patch at #2094145: document Form API #process callback in form.api.php.

Status: Needs review » Needs work

The last submitted patch, 2096731.drupal.form-process-pass-by-reference.patch, failed testing.

joachim’s picture

I have no idea why this would be failing.
Maybe it's a peculiarity of call_user_func_array() I'm not aware of?

joachim’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 1: 2096731.drupal.form-process-pass-by-reference.patch, failed testing.

farfanfelipe’s picture

TorontoSprint: This issue should be close because the core code has changed and the patch/issue does not apply anymore.
New code for the form_builder function is as follow.

function form_builder($form_id, &$element, &$form_state) {
  return \Drupal::formBuilder()->doBuildForm($form_id, $element, $form_state);
}
farfanfelipe’s picture

Issue summary: View changes
Status: Needs work » Closed (fixed)
smk-ka’s picture

Status: Closed (fixed) » Needs review
StatusFileSize
new822 bytes

This had actually never been fixed, let's try it again.

Status: Needs review » Needs work

The last submitted patch, 8: form_builder-2096731-8.patch, failed testing.

smk-ka’s picture

Status: Needs work » Closed (works as designed)

This change seems to break some form elements, as you'll get errors like Notice: Undefined index: #value in template_preprocess_form_element(). So it seems like it is required by some obscure code depending on it. 'Works as designed' probably describes the situation best.