CodeExplorer dblog_filters example
/**
* {@inheritdoc}
*/
public function getFormId() { return 'dblog_filter_form';
} /**
* {@inheritdoc}
*/
public function buildForm(array
$form, FormStateInterface
$form_state) { $filters =
dblog_filters();
$form['filters'
] =
[ '#type' => 'details',
'#title' =>
$this->
t('Filter log messages'
),
'#open' => TRUE,
];
$session_filters =
$this->
getRequest()->
getSession()->
get('dblog_overview_filter',
[]);
foreach ($filters as $key =>
$filter) { $form['filters'
]['status'
][$key] =
[ '#title' =>
$filter['title'
],
'#type' => 'select',
protected function buildFilterQuery(Request
$request) { $session_filters =
$request->
getSession()->
get('dblog_overview_filter',
[]);
if (empty($session_filters)) { return;
} $this->
moduleHandler()->
loadInclude('dblog', 'admin.inc'
);
$filters =
dblog_filters();
// Build query.
$where =
$args =
[];
foreach ($session_filters as $key =>
$filter) { $filter_where =
[];
foreach ($filter as $value) { $filter_where[] =
$filters[$key]['where'
];
$args[] =
$value;
} if (!
empty($filter_where)) { $where[] = '(' .
implode(' OR ',
$filter_where) . ')';
}