public function RequestParam::evaluate in Condition Query 8
Evaluates the condition and returns TRUE or FALSE accordingly.
Return value
bool TRUE if the condition has been met, FALSE otherwise.
Overrides ConditionInterface::evaluate
File
- src/
Plugin/ Condition/ RequestParam.php, line 102
Class
- RequestParam
- Provides a 'Request Param' condition.
Namespace
Drupal\condition_query\Plugin\ConditionCode
public function evaluate() {
// Convert params to lowercase.
$params = mb_strtolower($this->configuration['request_param']);
if (!$params) {
return TRUE;
}
$request = $this->requestStack
->getCurrentRequest();
parse_str(preg_replace('/\\n|\\r\\n?/', '&', $params), $request_params);
if (!empty($request_params)) {
foreach ($request_params as $key => $values) {
if (!is_array($values)) {
$values = [
$values,
];
}
$query_param_value = $request
->get($key);
if (!isset($query_param_value)) {
continue;
}
if (is_array($query_param_value)) {
foreach ($query_param_value as $array_value) {
if (in_array($array_value, $values)) {
return TRUE;
}
}
}
elseif (in_array($query_param_value, $values)) {
return TRUE;
}
}
}
return FALSE;
}