由于项目中的某些最后一分钟更改,我正在尝试更改自动填充字段的结果,例如删除已使用名称为"空"的分类术语标记的某些节点。
我已经成功创建了自己的选择处理程序,并在我的自定义表单上调用它。
在我的选择处理程序中,我正在使用entityQueryAlter
方法为查询添加条件:
class MyCustomSelection extends NodeSelection {
public function entityQueryAlter(SelectInterface $query) {
parent::entityQueryAlter($query);
//Get the tid for the term which was used to tag nodes which should be EXCLUDED from the results
$emptyTid = array_values(\Drupal::entityQuery('taxonomy_term')
->condition('name', 'Empty')
->execute())[0];
if ($emptyTid != null && $emptyTid > -1) {
//Get nids for nodes which were tagged with this term
$excludeQuery = db_query('
SELECT entity_id
FROM node__field_custom_tags
WHERE field_custom_tags_target_id = :tid',
array(
':tid' => $emptyTid
)
)->fetchAllKeyed(0, 0);
//Reset array keys
$result = array_values($excludeQuery);
//Typecast all the values to int, just to be safe
$typecastedResult = array();
foreach ($result as $k => $v) {
$typecastedResult[] = (int)$v;
}
//Add a condition to the query such as to exclude the nodes found above
$query->condition('entity_id', $typecastedResult, 'NOT IN');
}
return $query;
}
我理解使用db_select
而不是db_query
被视为最佳做法,但上述方法返回了我需要的结果,并且所有内容似乎都按预期工作,但事实是只有包含$query->condition
行时,我的自动填充字段才会无限期加载:
$query->condition('entity_id', $typecastedResult, 'NOT IN');
$typecastedResult
中的值等同于以下数组:
Array
(
[0] => 100
[1] => 101
etc...
)
有人可以提供一些见解,说明为什么自动填充字段会无限期地加载而没有结果吗?再一次,它是添加导致此行为的新条件。
答案 0 :(得分:0)
我刚刚解决了这个问题。出于某种原因,我没有生成错误日志。解决了这个问题后,问题很简单=> " ENTITY_ID"因为我们要查询node_field_data表,所以是错误的。正确的字段是node_field_data.nid。大多数问题是由于简单的错误:) ..多么令人尴尬