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