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