Drupal 8 YAML表单模块:填充选择元素 [英] Drupal 8 YAML Form Module: Populate Select Element

查看:72
本文介绍了Drupal 8 YAML表单模块:填充选择元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Drupal的新手,我正在尝试使用 YAML表单模块在Drupal 8中创建自定义表单:
https://www.drupal.org/project/yamlform

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.

我该怎么做?

预先感谢!

推荐答案

我不知道这是否是最好的方法,但这对我有用:

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

我已经在 .module中创建了一个自定义模块文件我已经实现了钩子 hook_yamlform_options_YAMLFORM_OPTIONS_ID_alter(),当部分 YAMLFORM_OPTIONS_ID 是一组自定义选项的ID时,已在选项页面(admin / structure / yamlform / settings / options / manage)中添加。
钩子的代码基本上是从数据库中获取数据并将其设置在具有所需键和值的 $ options 数组中。

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.

这篇关于Drupal 8 YAML表单模块:填充选择元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆