【问题标题】:Add Entity Reference to Drupal 8 Form Field?将实体引用添加到 Drupal 8 表单字段?
【发布时间】:2016-08-10 07:28:38
【问题描述】:

用户如何使用自动完成字段将产品添加到简单的插件配置中?

我尝试使用 Config Entity,但它看起来与 Form API 相同(我不能在那里使用实体字段)。

【问题讨论】:

    标签: forms drupal drupal-8


    【解决方案1】:

    我可以在 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',
    ];
    

    【讨论】:

    • 这行得通!谢谢。我完成了添加自定义 ContentEntityType。虽然它更复杂。但它也提供了更大的灵活性。
    • 你从我这里得到一个拳头泵
    【解决方案2】:

    使用webform - 有一个实体引用字段。 这不适用于您的目的..但您可以检查一下来源。

    【讨论】:

    • 这个问题是在 2016 年 8 月 10 日提出的,而不是在 2010 年提出的。
    • true - webform 和 eform 都有意义.. 但如果有人想通过 UI 创建表单,这是一个不错的选择
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-25
    • 1970-01-01
    • 2013-02-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多