expertszuloo.blogg.se

Drupal 8 form api example
Drupal 8 form api example








drupal 8 form api example

Though the more I analyze, the more I come to the conclusion that the #group approach might lead to a more robust code in the end. It’s quite visual to see nested arrays and understand which elements included in a certain container.īoth approaches are good enough to be used. Debugging forms grouped by #group property isn’t as nice as nested form elements.And official documentation won’t help them to understand. The most important disadvantage – it’s poorly documented and your coworkers might not understand what your code is doing.Now the same approach is being used by the Views UI module and Field Group which means following it makes your code a bit more consistent with titans of the Drupal world.Using a flat structure and #group approach eliminates these sorts of issues. Especially, when the project isn’t documented properly (and tell me, which project is). If someone’s form_alter relies on a given form hierarchy, any changes to it can be quite destructive. Quite often, changing a form element hierarchy can cause unexpected issues with third-party form_alters.The main difference is relevant for developers only since the #group approach makes the code much more predictive for long-term projects. This feature was committed in the core approximately 7 years ago (proof: ) and despite there is no public documentation about it.Įven more, when you try to google something like “#group FAPI Drupal 8”, you always land on tutorials for Group module.Įxamples of #group property usage: $form = [įor those, who have forgotten, the old-good nesting approach is the following: $form = [īoth snippets shown above are nearly identical and result in the same kind of HTML markup. Just spend a half an hour scrolling through some random code and you will find out some peculiar undocumented features.Īfter not-so-short research, it appeared that #group property can be used instead of nesting child elements into parent containers, fieldsets, etc. I needed Field Group integration so badly and started an investigation without having much of a choice. And clearly, this was not for fieldsets only. Field Group heavily uses the #group property which I was not aware of at the time.It does not have any place where form elements are being nested/grouped in each other.Specifies a group that can be used to group fieldsets into vertical tabs.ĭespite its single purpose, I’ve noticed two things in a Field Group module: The FAPI documentation clearly states that this property is being used to group fieldsets into vertical tabs. Most likely, you’ve never needed to.ĭuring our effort of integrating Product Builder with the Field Group module, I’ve got stuck with understanding this property. See also the documentation on advanced search operators.I am not sure whether you ever seen the tiny #group property located on the iconic Form API guide.

drupal 8 form api example

'select#edit-settings-query-mode' => array( 'value' => 'search'), '#default_value' => isset( $bean-> settings) ? $bean-> settings : '', Use "list" option for multiple names, where possible.'), '#description' => t( 'One or more twitter screen names, separated by commas. 'select#edit-settings-query-mode' => array( 'value' => 'user'),










Drupal 8 form api example