gpt4 book ai didi

drupal - 使用引用字段中的动态参数过滤实体引用 View

转载 作者:行者123 更新时间:2023-12-05 06:31:06 27 4
gpt4 key购买 nike

我需要通过从我的内容类型中的“引用字段”传递参数来过滤“实体引用 View ”自动完成小部件。

Autocomplete by URL

我对此进行了研究,发现 PHP 代码类型上下文过滤器是实现此目标的最推荐方法,但由于 PHP 代码现已从 Drupal 8 核心中删除,这种常见用例的替代方案是什么? (较早的建议使用 PHP 代码:Drupal 7: how to filter view content (with entity reference field) based on current page content)

在编辑引用字段时,似乎在“查看参数”字段中仅提及硬编码值,并且没有实现此目的的动态方式(例如从 URL/查询字符串等)。

View Arguments field

最佳答案

这很老套,但您可以使用 hook_form_alter。下面是一个将当前 NID 作为参数传递的示例:

/**
* Implements hook_form_alter().
*/
function MYMODULE_form_alter(&$form, FormStateInterface $form_state, $form_id)
{

if ($form_id == 'node_NODETYPE_edit_form') {
$node = $form_state->getFormObject()->getEntity();
$form['field_MY_REF_FIELD']['widget'][0]['target_id']['#selection_settings']['view']['arguments'][0] = $node->id();
}
}

关于drupal - 使用引用字段中的动态参数过滤实体引用 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51899076/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com