php remove_empty_filters_views_query.php
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php remove_empty_filters_views_query.php相关的知识,希望对你有一定的参考价值。
/**
* Implements hook_views_query_alter().
*/
function mymodule_views_query_alter(ViewExecutable $view, QueryPluginBase $query) {
if ('wm_users' == $view->id() && 'page_1' == $view->current_display) {
// We don't want to filter the values when the filter value is empty.
$filters = [ // Filters to unset from query when they are empty
'id_1',
'id',
];
$fields = [];
foreach ($filters as $filter_name) {
if (isset($view->filter[$filter_name])) {
$fields[] = $view->filter[$filter_name]->relationship . '.' . $view->filter[$filter_name]->field;
}
}
if ($fields) {
foreach ($query->where as &$where_group) {
foreach ($where_group['conditions'] as $key => $condition) {
$match = array_search($condition['field'], $fields);
if (FALSE !== $match) {
if (empty($condition['value'])) {
unset($where_group['conditions'][$key]);
}
unset($fields[$match]);
if (!$fields) {
break 2;
}
}
}
}
}
}
}
以上是关于php remove_empty_filters_views_query.php的主要内容,如果未能解决你的问题,请参考以下文章
php PHP__YII__controller
php PHP __ $ _ SESSION - $ _ COKKIE
php php__newline.php
require(dirname(__FILE__).'/'.'myParent.php') 比 require('myParent.php') 有啥好处?
php PHP __ $ _ POST / $ _GET / $ _REQUEST
PHP的 __DIR__ 作用