如何将实体引用添加为表单字段drupal 8?我有可能吗?

Prz*_*cki 2 drupal-8

我想要实现的是插件的简单配置.我需要实体参考字段,用户可以使用自动完成字段将某些产品添加到配置中.我试图使用Config Entity,但它看起来和Form Api看起来一样,我不能在那里使用实体字段.我等不及要你回复了.

nra*_*eff 9

我能够使用表单API和entity_autocomplete类型在Drupal 8中完成此操作.

$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',
];
Run Code Online (Sandbox Code Playgroud)