Drupal 8 YAML Form Module: Populate Select Element

柔情痞子 提交于 2019-12-13 07:38:16

问题


I'm a newbie in Drupal and I'm trying to create custom forms in Drupal 8 using 'YAML Form' module: https://www.drupal.org/project/yamlform

I have added some 'select' elements with some custom options from the Form elements page provided by the module, but I don't find the way to populate these elements from database.

How can I do it? Step by step if possible, please.

Thanks in advance!


回答1:


I don't know if it's the best way to do it but it works for me:

I've created a custom module and in the '.module' file I've implemented the hook hook_yamlform_options_YAMLFORM_OPTIONS_ID_alter() when the part YAMLFORM_OPTIONS_ID is the ID of a custom set of options I've added in the Options page (admin/structure/yamlform/settings/options/manage). The code of the hook, basically, gets data from database and sets it in the $options array with the desired keys and values.

Then when I access to the Options page again, in the row of the new custom set of options, the column ALTERED has the value 'Yes'. Click to 'Edit' this row and then click to 'Reset' button. The result is that the options value/text table is updated automatically with the data returned from database.



来源:https://stackoverflow.com/questions/40421252/drupal-8-yaml-form-module-populate-select-element

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!