【发布时间】:2018-01-11 15:08:18
【问题描述】:
在 drupal 8 中,是否可以使用引用实体创建复杂的配置实体?例如,在一个配置实体字段中链接多个节点?我还没有找到文档...
【问题讨论】:
在 drupal 8 中,是否可以使用引用实体创建复杂的配置实体?例如,在一个配置实体字段中链接多个节点?我还没有找到文档...
【问题讨论】:
我不确定我是否理解你的问题,但我会给你一些线索来解决你的问题。
对不起,如果我的答案不符合您的需要。
您只想要一个链接多个节点的配置字段吗?
或
您想要自定义配置实体吗?
使用 entity_autocomplete 字段会对您有所帮助。 此处提供额外文档:https://www.drupal.org/node/2418529
用法:
/**
* @file
* Contains A custom Class Form.
*/
// ... Namespaces & uses.
class AdminForm extends FormBase {
// Class definitions
public function buildForm(array $form, FormStateInterface $form_state, $extra = NULL) {
$form['node_collection'] = array(
'#type' => 'entity_autocomplete',
'#target_type' => 'node',
'#title' => 'Nodes',
);
}
}
然后您应该将其保存在 State 或 Config API 中。
查看这篇文章以了解两者之间的区别(它将帮助您选择正确的):https://antistatique.net/en/we/blog/2016/06/14/drupal-8-differences-between-configuration-api-state-api
您应该查看有关配置实体的文档: https://www.drupal.org/docs/8/api/configuration-api/creating-a-configuration-entity-type-in-drupal-8
然后,您可以查看此答案,它将帮助您为节点或您想要的任何实体创建一个 entity_reference 字段。
Retrieve a taxonomy term in the buildrow function of a drupal 8 custom entity
希望对你有帮助!
【讨论】: