Post upgrading from Drupal 9.5.10 to Drupal 10.1.3, I was seeing the following error when viewing a view page:
TypeError: Cannot assign null to property Drupal\views\Plugin\views\argument\ArgumentPluginBase::$operator of type string in Drupal\views\Plugin\views\argument\ArgumentPluginBase->unpackArgumentValue() (line 1310 of core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php).
Finding an insight to this error was on the following Drupal issues page - https://www.drupal.org/project/drupal/issues/3353786
Where, line 111 of the ArgumentPluginBase.php file originally was
/**
* Is argument a default.
*/
public bool $is_default;
/**
* The operator used for the query: or|and.
*/
public string $operator;
/**
* The title set by argument validation.
*/
public ?string $validated_title;
The line 'public string $operator;' need to change to
public ?string $operator;
Obviously, this change cannot be directly be applied to core code. Instead a patch is required for this to be applied.
How do you create a patch?
Creating a patch
Current path to the file: web/core/modules/views/src/Plugin/views/argument/
Orignal filename: ArgumentPluginBase.php
Adjusted filename: ArgumentPluginBase-adjusted.php
Create a Patch
A patch is used to create or override changes in another file. The command to create a patch is:
diff -u {original filename} {changed filename} > {patchfile}.patch
diff -u web/core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php web/core/modules/views/src/Plugin/views/argument/ArgumentPluginBase-adjusted.php > patches/argument-plugin-base-operator.patch
Response:
--- web/core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php 2023-09-08 01:19:51
+++ web/core/modules/views/src/Plugin/views/argument/ArgumentPluginBase-adjusted.php 2023-09-18 21:52:15
@@ -108,7 +108,7 @@
/**
* The operator used for the query: or|and.
*/
- public string $operator;
+ public ?string $operator;
/**
* The title set by argument validation.