[PHP8.1] "Order #@order_id created." log message triggers htmlspecialchars() deprecation

Created on 3 October 2022, over 2 years ago
Updated 23 August 2023, over 1 year ago

Problem/Motivation

\Drupal\commerce_webform_order\Plugin\WebformHandler\CommerceWebformOrderHandler::postSave() adds a log message when an order is created:

        // Log message in Webform's submission log.
        $context = [
          '@order_id' => $this->cart->get('order_id')->getString(),
          '@owner_email' => $this->cart->getEmail(),
          'webform_submission' => $webform_submission,
          'handler_id' => $this->getHandlerId(),
          'data' => [],
        ];
        if ($this->cart->getEmail() !== NULL) {
          $this->getLogger('webform_submission')->notice("Order #@order_id created to '@owner_email'.", $context);
        }
        else {
          $this->getLogger('webform_submission')->notice("Order #@order_id created.", $context);
        }

When this->cart->getEmail() is NULL, the @owner_email parameter triggers a PHP warning:

Deprecated function: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\Component\Utility\Html::escape()

Proposed resolution

Update the log message so it does not define a string argument with a NULL value.

Remaining tasks

  1. Write a patch
  2. Review
  3. Commit

User interface changes

None.

API changes

None.

Data model changes

None.

📌 Task
Status

Fixed

Version

3.0

Component

Code

Created by

🇳🇱Netherlands idebr

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024