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 Fletcher04 Apr 2025
Managing .gitignore changes
When working with Git, the .gitignore file plays a critical role in controlling which files and folders are tracked by version control. Yet, many developers are unsure when changes to .gitignore take effect and how to manage files that are already being tracked. This uncertainty can lead to...
Andrew Fletcher26 Mar 2025
How to fix the ‘Undefined function t’ error in Drupal 10 or 11 code
Upgrading to Drupal 10.4+ you might have noticed a warning in their code editor stating “Undefined function ‘t’”. While Drupal’s `t()` function remains valid in procedural code, some language analysis tools — such as Intelephense — do not automatically recognise Drupal’s global functions. This...
Andrew Fletcher17 Mar 2025
Upgrading to PHP 8.4 challenges with Drupal contrib modules
The upgrade from PHP 8.3.14 to PHP 8.4.4 presents challenges for Drupal 10.4 websites, particularly when dealing with contributed modules. While Drupal core operates seamlessly, various contrib modules have not yet been updated to accommodate changes introduced in PHP 8.4.x. This has resulted in...