简体   繁体   English

如何添加实体引用作为表单字段drupal 8? 我可以吗?

[英]How to add entity reference as a form field drupal 8? I it possible?

What I'm trying to achieve is simple config for a plugin. 我想要实现的是插件的简单配置。 I need entity reference field where users can add certain products to the config using autocomplete field. 我需要实体参考字段,用户可以在其中使用自动完成字段将某些产品添加到配置中。 I tried to use Config Entity but It seems to look the same as Form Api and I can't use entity fields there. 我尝试使用Config Entity,但它看起来与Form Api相同,并且无法在其中使用实体字段。 I can't wait to see you reply. 我等不及要看到您的回复。

I was able to do this in Drupal 8 using the form API and the entity_autocomplete type. 我能够在Drupal 8中使用API​​形式和entity_autocomplete类型来做到这一点。

$form['stories'] = [
    '#type' => 'entity_autocomplete',
    '#target_type' => 'node',
    '#title' => $this->t('Stories'),
    '#description' => $this->t('Select some stories.'),
    '#default_value' => $default_entities,
    '#tags' => TRUE,
    '#selection_settings' => array(
        'target_bundles' => array('page', 'article'),
    ),
    '#weight' => '0',
];

Use webform - there is an entity reference field. 使用网络表单 -有一个实体参考字段。 This won't be useable for your purpose .. but you can check the source for sake. 这将无法用于您的目的..但是您可以查看源代码。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何以编程方式在Drupal 8中创建实体引用字段? - How to create an entity reference field in Drupal 8 programmatically? 如何以编程方式设置节点 > 图像实体引用字段值,其中我在 drupal 8 节点编辑表单中具有 fid 值 - How to programmatically set node > Image entity reference field value where I have fid value in drupal 8 node edit form Drupal 8:如何自定义表单窗口小部件以显示实体字段值而不是实体标题? - Drupal 8: How do I customize a form widget to show an entity field value instead of the entity title? 如何在Drupal 8的自定义实体的图像字段中添加alt和title字段 - How to add the alt and title fields in an image field of a custom entity in drupal 8 在 Drupal 8. Drupal 商务。 如何根据产品字段隐藏视图(实体参考 - 分类) - In Drupal 8. Drupal Commerce. How to hide a view based on Product field (Entity Reference - Taxonomy) Drupal8如何在树枝中创建到实体添加表单的链接 - Drupal8 How to create a link to an entity add form in twig Drupal 8:如何创建内容引用/文本区域复合字段? - Drupal 8: How do I create a content reference/textarea compound field? 如何在 Drupal8 中向“站点信息”表单添加新的自定义字段 - How to add a new custom field to "Site Infomation" Form in Drupal8 Drupal 8 - 实体参考 - 自动完成 - 添加字段以进行搜索并导致自动完成 - Drupal 8 - Entity Reference - Autocomplete - Add fields to search and result in autocomplete 如何在Drupal 8菜单项中添加额外的字段。 我想添加一个额外的图像字段 - How can I add an extra field in Drupal 8 menu Item. I want to add an extra image field
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM