I am trying to port over a D7 module and am stuck on how to do this step. How can I enter values into a node add form (that the user can override if desired)?

The code sets the [#default_value] for the form field, i.e.

  foreach ($isbn2book_data as $field => $default_value) {
    switch ($field) {
      case 'title':
        $form[$field]['#default_value'] = $default_value;
        break;
      default:
        $form[$field]['und']['0']['value']['#default_value'] = $default_value;
        break;
    }
  }

It works in D7. The form object appears to have the same structure in Backdrop, but the (converted) code doesn't work on it. If I print a debug message with the value of the $form object, I can see that the default values are set correctly, but they don't show up on the form display.

Any help appreciated!

(Following up on the book data module topic here: https://forum.backdropcms.org/forum/book-data-module)

Accepted answer

Hi @leeksoup.

Compare the top of the function call. If you used Coder Upgrade on PHP 8+ then it often strips out the & from parameters, so &$form_state becomes $form_state

Sounds like this might be the case here

Most helpful answers

Hi @leeksoup

I raised your suggestion in the chat channel:

https://backdrop.zulipchat.com/#narrow/stream/218635-Backdrop/topic/Code...

And the response is positive.  I'll update here where it goes in, unless you decide to join the chat channel.

Thank you.

Comments

Hi @leeksoup.

Compare the top of the function call. If you used Coder Upgrade on PHP 8+ then it often strips out the & from parameters, so &$form_state becomes $form_state

Sounds like this might be the case here

You are exactly correct! Thank you so much! I'll go through and check all the function calls for this issue. I can see how that would make a difference. I totally overlooked that possibility. :facepalm:

Guess I should have tried Coder Upgrade with php 7.4 (as you suggested on the other thread) but it is a rather involved process to get that set up on my dev system. 

@yorkshirepudding - Could PHP 7.4 be added to the install requirements for Coder Upgrade? Or at least linked to the issues queue to alert users that if they use PHP 8+ these unhappy results can be expected?

Thanks again for your help with this.