Skip to main content

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.


 

 

Related articles

Andrew Fletcher22 Nov 2023
Fatal error: Maximum execution time of 30 seconds exceeded in ...
When reloading a page, you may encounter the following error:Fatal error: Maximum execution time of 30 seconds exceeded in /var/www/html/content/core/lib/Drupal/Core/{some file .php} on line n SolutionTo resolve this issue, you need to adjust the max_execution_time parameter in the php.ini...
Andrew Fletcher16 Nov 2023
Drupal and AWS - over 300 simultaneous database connections
The issue of over 300 simultaneous database connections in the context of AWS and Drupal can have several potential causes. Here are some common factors to consider:Server ConfigurationCheck your server configuration to ensure it can handle the expected number of simultaneous connections. This...