プロジェクトの最後の一部の変更により、オートコンプリートフィールドの結果を変更して、タクソノミー用語でタグ付けされた特定のノードを削除しようとしています。名前は "空"です。Drupal 8 - entity_autocompleteのカスタム選択ハンドラにより、不定のロードが発生する
自分のセレクションハンドラを正常に作成しましたが、カスタムフォームで呼び出されています。私はそれがdb_query
上db_select
を使用することがベストプラクティスと考えられていることを理解しますが、上記
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;
}
:entityQueryAlter
方法の私の選択ハンドラで
$query->condition
行が含まれている場合という事実を除いて、期待通りに動作しているようだ:
$query->condition('entity_id', $typecastedResult, 'NOT IN');
$typecastedResult
の値は次の配列に相当します。
Array
(
[0] => 100
[1] => 101
etc...
)
誰かが自動補完フィールドは結果なしで無期限にロードすることになる理由をいくつかの洞察を提供していただけますか?もう一度、この動作を引き起こすのは新しい状態の追加です。