0

我有一种情况,我必须在词汇表视图的上下文过滤器中添加一个 0-9 链接

如何更改 where 子句部分?我需要改变

SUBSTRING(node.title, 1, :node_title) = :node_title1

SUBSTRING(node.title, 1, 1) =REGEXP ('[0-9]')

如果某个值 == '0-9' 我试图实现 hook_views_query_alter 但它不起作用

function  custom_views_query_alter(&$view, &$query){

  $current_view=&$view;

  switch($current_view->name){

    case  'glossary':

  if($query->where[0]['conditions'][0]['value'][':node_title1']=='0-9'){
    $query->where[0]['conditions'][0]['field']= "SUBSTRING(node.title, 1, 1) =REGEXP ('[0-9]')";
    echo "YES";

    dpm($query->where);
        }  } }
4

1 回答 1

0

我设法让它工作这里的代码

function  custom_views_query_alter(&$view, &$query){

$current_view=&$view;
switch($current_view->name){

case  'glossary':
  if($query->where){

  if($query->where[0]['conditions'][0]['value'][':node_title1']=="0-9"){
       $query->where[0]['conditions'][0]['field'] = "SUBSTRING(node.title, 1, 1) REGEXP ('[0-9]')";
    dpm($query->where);
 }

}
}
}
于 2012-09-24T19:40:43.417 回答