- Issue created by @marthinal
- Merge request !635#3523961: Avoid addcslashes() deprecation warning during Webform submission preview → (Open) created by Unnamed author
- 🇪🇨Ecuador jwilson3
In PHP 8.3, a deprecation warning is triggered when the addcslashes()
function receives NULL
instead of a string for its first parameter. This warning occurs in the Webform module when previewing nodes containing webforms. Specifically, the issue happens in WebformSubmissionForm::displayMessages()
when getStorage()->getTotal()
is called during node preview and processes a database query that may contain null values, leading to:
Deprecated function: addcslashes(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\Core\Database\Connection->escapeLike() (line 1392 of core/lib/Drupal/Core/Database/Connection.php).
Modify the conditional statement in WebformSubmissionForm::displayMessages()
that checks for previous submissions to avoid executing database queries with potentially null values during node preview operations:
// Display link to previous submissions message when user is adding a new submission. if ( $this->isGet() && $this->operation === 'add' && !str_ends_with($this->getRouteMatch()->getRouteName(), '.preview') && $this->getWebformSetting('form_previous_submissions', FALSE) && ($webform->access('submission_view_own') || $this->currentUser()->hasPermission('view own webform submission')) // Add this line to check if the source entity is in preview mode && !($this->sourceEntity && $this->sourceEntity->hasField('in_preview') && !empty($this->sourceEntity->in_preview)) && ($previous_submission_total = $this->getStorage()->getTotal($webform, $this->sourceEntity, $this->currentUser())) ) { // ...remaining code... }
This prevents the code from attempting to calculate submission totals when a node is in preview mode, avoiding the database queries that trigger the deprecation warning.
None. The fix only prevents deprecation warnings without changing any user-facing functionality.
None. This is a defensive coding fix to avoid passing null values to addcslashes()
.
None.
Needs work
6.3
Code