drupal 8 views 自定义 查询 query hook_views_query_alter()

这里提供两种模式

function pgdb_entity_views_query_alter($view, $query)
{
    if ($view->id() == 'personal_information') {
        foreach ($query->where as &$condition_group) {
            foreach ($condition_group['conditions'] as $i=> &$condition) {
                //phone field, default is ILIKE
                if ($condition['field'] == 'node.phone') {
                    $condition = [
                        'field' => 'node.phone',
                        'value' => $view->exposed_raw_input['phone'],
                        'operator' => "=",
                    ];
                }
                //address, use for Postgresql tsvector field type
                if ($condition['field'] == 'node.address') {
                    dpm($condition_group['conditions'] );
                    unset($condition_group['conditions'][$i]);
                    $query->addWhereExpression('', "node.tsvector_address @@ to_tsquery('" . $view->exposed_raw_input['address'] . "')");
                }
            }
        }
    }
}

分类