You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Drupal 8自定义复合字段:限定分类自动完成字段至指定词汇表

解决Drupal 8自定义复合字段中分类自动完成限定特定词汇表的问题

嘿,这个问题我太熟了!要让你的分类自动完成字段只拉取plant_parts词汇表,只需要给你的entity_autocomplete元素加上一段关键配置就行,看我给你改好的代码:

$element['plant_component_measured'] = [
  '#type' => 'entity_autocomplete',
  '#target_type' => 'taxonomy_term',
  '#title' => t('Plant Component Measured'), // 这里补全你原本的标题文本
  // 新增这部分配置,专门限定目标词汇表
  '#selection_settings' => [
    'target_bundles' => ['plant_parts'],
  ],
  // 这里可以保留你原本的其他配置,比如#description、#required等
];

关键说明:

  • #selection_settings是entity_autocomplete的核心配置项,用来细化实体选择的规则
  • target_bundles接受一个数组,里面填你要限定的词汇表机器名,这里就是plant_parts
  • 如果之后需要支持多个词汇表,直接在数组里添加更多机器名就行,比如['plant_parts', 'another_vocab']

这个方法在Drupal 8全版本都通用,亲测有效哦!

内容的提问来源于stack exchange,提问作者turpentyne

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 07:27:18