By ovp


2019-02-07 16:08:52 8 Comments

I'm still pretty new to Drupal and had a question about the node-edit-form twig template. In them template, you can render {{form}}, {{form.advanced}}, and {{form.actions}} but when using xdebug, the form variable doesn't actually have those values in the array. How are those being processed? I'm curious now i'f I've missed this in other twig templates for other arrays/objects.

2 comments

@ovp 2019-02-11 15:10:36

VSCode by default sets a limit at ~32 max elements to display in an array so it was truncating the rest. I followed the advice in this post to fix the issue -- which was simply adding the xdebugSettings to the launch.json file in vscode.

       {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9000,
            "xdebugSettings": {
                "max_children": 999,
            }   
        }

@4k4 2019-02-07 16:47:00

When you xdebug $variables in a preprocess hook

function mymodule/mytheme_preprocess_node_edit_form(&$variables) {

}

you find $variables['form']['actions'] and the other form elements. You can also install a module to set a breakpoint in the twig template directly, see https://www.drupal.org/docs/8/theming/twig/debugging-twig-templates

What you now have is probably the form build $form in a different place.

@ovp 2019-02-07 19:11:46

That's certainly how I've handled everything else ( I have both xdebug running in my environment and devel for breakpoints in twig templates ), however, in this specific case there isn't actually an 'actions' or 'advanced' property in the $vars['form'] array. the only properties on the form array that aren't render array properties ( like $variables['form']['#something']) are $variables['form']['meta'] and $variables['form']['menu'] properties. Does the form check the form_state before the form itself and compiles based on that?

@4k4 2019-02-07 20:57:56

I see 23 top level form elements + 28 #-properties in $variables['form'] when I stop in the preprocess hook . What do you mean by "in this specific case", what is specific? - To your last question, a form can be built based on $form_state. For a normal form it is rather empty on the first form build, so it's more about rebuilding the form depending on user input, but especially in an entity form it contains already the entity object prefilled with default values.

@ovp 2019-02-11 15:07:06

Wow... I didn't even think about it until you mentioned it but I have a similar number of total array elements but I can only see ~30 of them in the debugger output in vscode. I found this thread stackoverflow.com/questions/49752153/… that fixed the issue. Thanks for your help!

Related Questions

Sponsored Content

2 Answered Questions

Get $form_state values from individual entity form fields

  • 2017-11-15 10:01:58
  • Marius Ilie
  • 1555 View
  • 1 Score
  • 2 Answer
  • Tags:   8 forms entities

1 Answered Questions

[SOLVED] Is this acceptable for passing data from a module to a template?

  • 2019-03-27 04:16:24
  • mrlexington
  • 33 View
  • 0 Score
  • 1 Answer
  • Tags:   8 theming

1 Answered Questions

[SOLVED] Render field values in node template

  • 2018-08-17 16:16:46
  • chalo
  • 142 View
  • 0 Score
  • 1 Answer
  • Tags:   8

1 Answered Questions

[SOLVED] How do I assign a template to the user edit form?

  • 2017-05-20 20:00:37
  • Tyler Durden
  • 1119 View
  • 1 Score
  • 1 Answer
  • Tags:   theming users

0 Answered Questions

1 Answered Questions

[SOLVED] Drupal 8, use variable defined from custom form in custom template twig

  • 2016-10-05 20:37:11
  • user2137454
  • 1427 View
  • 1 Score
  • 1 Answer
  • Tags:   theming forms 8

2 Answered Questions

[SOLVED] How do I add a variable for a Twig template in my preprocess function?

  • 2015-08-15 19:36:13
  • Mad Scientist
  • 12543 View
  • 8 Score
  • 2 Answer
  • Tags:   8 theming

1 Answered Questions

[SOLVED] defining node multicolumn layout with twig template

  • 2016-09-10 09:24:07
  • DragonEye
  • 73 View
  • 0 Score
  • 1 Answer
  • Tags:   theming nodes 8

1 Answered Questions

[SOLVED] How to render a template in Drupal 8

  • 2014-11-07 15:25:39
  • user1015214
  • 13476 View
  • 11 Score
  • 1 Answer
  • Tags:   theming 8

1 Answered Questions

[SOLVED] How do I know when a render array will be processed properly?

  • 2014-10-30 11:17:31
  • ratface
  • 170 View
  • 1 Score
  • 1 Answer
  • Tags:   forms theming

Sponsored Content