Problem/Motivation
When the value is empty, getArgument() is NULL.
This return type is an issue when trying to validate the argument since Drupal\views\Plugin\views\argument_validator\Entity->validateArgument() uses the argument in preg_split, resulting in error #1.
This is later used in preg_match in Drupal\views\Plugin\views\HandlerBase::breakString() resulting in error #2.
Finally, it reaches Drupal\views\Plugin\views\argument\NumericArgument->query() and hits a TypeError:
TypeError: Cannot assign null to property Drupal\views\Plugin\views\argument\ArgumentPluginBase::$operator of type string in Drupal\views\Plugin\views\argument\NumericArgument->query() (line 96 of /home/{USER}/public_html/core/modules/views/src/Plugin/views/argument/NumericArgument.php).
Steps to reproduce
Note: this is untested, but should theoretically work.
- Install Drupal 10.1
- Create a view with a user contextual filter with a default value set by views_arg_entity_field.
- Visit the view using the anonymous user.
- Note the error.
Proposed resolution
Return the empty string if the return value is NULL.
Remaining tasks
Figure out if the module ever returns NULL in regularly functionality.
User interface changes
N/A.
API changes
getArgument() returns an empty string rather than NULL
Data model changes
N/A.
Errors
Error #1
Deprecated function: preg_split(): Passing null to parameter #2 ($subject) of type string is deprecated in Drupal\views\Plugin\views\argument_validator\Entity->validateArgument() (line 183 of /home/{USER}/public_html/core/modules/views/src/Plugin/views/argument_validator/Entity.php)
#0 /home/{USER}/public_html/core/includes/bootstrap.inc(164): _drupal_error_handler_real(8192, 'preg_split(): P...', '/home/{USER}/...', 183)
#1 [internal function]: _drupal_error_handler(8192, 'preg_split(): P...', '/home/{USER}/...', 183)
#2 /home/{USER}/public_html/core/modules/views/src/Plugin/views/argument_validator/Entity.php(183): preg_split('/[,+ ]/', NULL)
#3 /home/{USER}/public_html/core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php(1066): Drupal\views\Plugin\views\argument_validator\Entity->validateArgument(NULL)
#4 /home/{USER}/public_html/core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php(1101): Drupal\views\Plugin\views\argument\ArgumentPluginBase->validateArgument(NULL)
#5 /home/{USER}/public_html/core/modules/views/src/ViewExecutable.php(1116): Drupal\views\Plugin\views\argument\ArgumentPluginBase->setArgument(NULL)
#6 /home/{USER}/public_html/core/modules/views/src/ViewExecutable.php(1282): Drupal\views\ViewExecutable->_buildArguments()
#7 /home/{USER}/public_html/core/modules/views/src/ViewExecutable.php(1406): Drupal\views\ViewExecutable->build(NULL)
#8 /home/{USER}/public_html/core/modules/views/src/ViewExecutable.php(1469): Drupal\views\ViewExecutable->execute(NULL)
Error #2
Deprecated function: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in Drupal\views\Plugin\views\HandlerBase::breakString() (line 752 of /home/{USER}/public_html/core/modules/views/src/Plugin/views/HandlerBase.php)
#0 /home/{USER}/public_html/core/includes/bootstrap.inc(164): _drupal_error_handler_real(8192, 'preg_match(): P...', '/home/{USER}/...', 752)
#1 [internal function]: _drupal_error_handler(8192, 'preg_match(): P...', '/home/{USER}/...', 752)
#2 /home/{USER}/public_html/core/modules/views/src/Plugin/views/HandlerBase.php(752): preg_match('/^([\\w0-9-_\\.]+...', NULL)
#3 /home/{USER}/public_html/core/modules/views/src/Plugin/views/argument/NumericArgument.php(94): Drupal\views\Plugin\views\HandlerBase::breakString(NULL, false)
#4 /home/{USER}/public_html/core/modules/views/src/ViewExecutable.php(1126): Drupal\views\Plugin\views\argument\NumericArgument->query(true)
#5 /home/{USER}/public_html/core/modules/views/src/ViewExecutable.php(1282): Drupal\views\ViewExecutable->_buildArguments()
#6 /home/{USER}/public_html/core/modules/views/src/ViewExecutable.php(1406): Drupal\views\ViewExecutable->build(NULL)
#7 /home/{USER}/public_html/core/modules/views/src/ViewExecutable.php(1469): Drupal\views\ViewExecutable->execute(NULL)