Commit 789895fd authored by catch's avatar catch
Browse files

Issue #3241280 by alexpott, Lendude: Fix PHP 8.1 deprecations caused by views code

parent 397d1997
......@@ -193,6 +193,9 @@ public function getField($field = NULL) {
* {@inheritdoc}
*/
public function sanitizeValue($value, $type = NULL) {
if ($value === NULL) {
return '';
}
switch ($type) {
case 'xss':
$value = Xss::filter($value);
......
......@@ -133,7 +133,8 @@ protected function getRoute($view_id, $display_id) {
];
// @todo How do we apply argument validation?
$bits = explode('/', $this->getOption('path'));
$path = $this->getOption('path');
// @todo Figure out validation/argument loading.
// Replace % with %views_arg for menu autoloading and add to the
// page arguments so the argument actually comes through.
......@@ -144,23 +145,27 @@ protected function getRoute($view_id, $display_id) {
$argument_map = [];
// Replace arguments in the views UI (defined via %) with parameters in
// routes (defined via {}). As a name for the parameter use arg_$key, so
// it can be pulled in the views controller from the request.
foreach ($bits as $pos => $bit) {
if ($bit == '%') {
// Generate the name of the parameter using the key of the argument
// handler.
$arg_id = 'arg_' . $arg_counter++;
$bits[$pos] = '{' . $arg_id . '}';
$argument_map[$arg_id] = $arg_id;
}
elseif (strpos($bit, '%') === 0) {
// Use the name defined in the path.
$parameter_name = substr($bit, 1);
$arg_id = 'arg_' . $arg_counter++;
$argument_map[$arg_id] = $parameter_name;
$bits[$pos] = '{' . $parameter_name . '}';
$bits = [];
if (is_string($path)) {
$bits = explode('/', $path);
// Replace arguments in the views UI (defined via %) with parameters in
// routes (defined via {}). As a name for the parameter use arg_$key, so
// it can be pulled in the views controller from the request.
foreach ($bits as $pos => $bit) {
if ($bit == '%') {
// Generate the name of the parameter using the key of the argument
// handler.
$arg_id = 'arg_' . $arg_counter++;
$bits[$pos] = '{' . $arg_id . '}';
$argument_map[$arg_id] = $arg_id;
}
elseif (strpos($bit, '%') === 0) {
// Use the name defined in the path.
$parameter_name = substr($bit, 1);
$arg_id = 'arg_' . $arg_counter++;
$argument_map[$arg_id] = $parameter_name;
$bits[$pos] = '{' . $parameter_name . '}';
}
}
}
......
......@@ -157,6 +157,8 @@ public function render(ResultRow $values) {
return '';
}
// After the hide_empty check NULL values should be treated as a 0 value.
$value = $value ?? 0;
if (!empty($this->options['set_precision'])) {
$precision = $this->options['precision'];
}
......
......@@ -111,8 +111,8 @@ public function groupByTestHelper($aggregation_function, $values) {
foreach ($view->result as $item) {
$results[$item->entity_test_name] = $item->id;
}
$this->assertEquals($values[0], $results['name1'], new FormattableMarkup('Aggregation with @aggregation_function and groupby name: name1 returned the expected amount of results', ['@aggregation_function' => $aggregation_function]));
$this->assertEquals($values[1], $results['name2'], new FormattableMarkup('Aggregation with @aggregation_function and groupby name: name2 returned the expected amount of results', ['@aggregation_function' => $aggregation_function]));
$this->assertEquals($values[0], $results['name1'], new FormattableMarkup('Aggregation with @aggregation_function and groupby name: name1 returned the expected amount of results', ['@aggregation_function' => $aggregation_function ?? 'NULL']));
$this->assertEquals($values[1], $results['name2'], new FormattableMarkup('Aggregation with @aggregation_function and groupby name: name2 returned the expected amount of results', ['@aggregation_function' => $aggregation_function ?? 'NULL']));
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment