2016-12-22 4 views
2

プロジェクトの最後の一部の変更により、オートコンプリートフィールドの結果を変更して、タクソノミー用語でタグ付けされた特定のノードを削除しようとしています。名前は "空"です。Drupal 8 - entity_autocompleteのカスタム選択ハンドラにより、不定のロードが発生する

自分のセレクションハンドラを正常に作成しましたが、カスタムフォームで呼び出されています。私はそれがdb_querydb_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方法の私の選択ハンドラで

、私が作っています使用することは、クエリに条件を追加しますこの方法は、私が必要とする結果を返して、すべてが私のオートコンプリートフィールドの負荷は無期限ONLY $query->condition行が含まれている場合という事実を除いて、期待通りに動作しているようだ:

$query->condition('entity_id', $typecastedResult, 'NOT IN'); 

$typecastedResultの値は次の配列に相当します。

Array 
(
    [0] => 100 
    [1] => 101 
    etc... 
) 

誰かが自動補完フィールドは結果なしで無期限にロードすることになる理由をいくつかの洞察を提供していただけますか?もう一度、この動作を引き起こすのは新しい状態の追加です。

答えて

0

私はちょうどこれを解決しました。何らかの理由で私はエラーログを生成していませんでした。これを修正して、node_field_dataテーブルを照会しているので、問題はシンプル=> "entity_id"が間違っていました。正しいフィールドはnode_field_data.nidです。ほとんどの問題は単純なエラーによるものです:)。どのように恥ずかしい

関連する問題