Problem/Motivation

When using PHP 8.1 the following error is displayed:

Deprecated function: preg_quote(): Passing null to parameter #1 ($str) of type string is deprecated in Drupal\Core\Path\PathMatcher->matchPath() (line 82 of core/lib/Drupal/Core/Path/PathMatcher.php).
Drupal\Core\Path\PathMatcher->matchPath('/admin/config', NULL) (Line: 1433)
mailchimp_page_bottom(Array) (Line: 355)
Drupal\Core\Render\MainContent\HtmlRenderer->buildPageTopAndBottom(Array) (Line: 150)

Steps to reproduce

  1. Using Drupal 9.3.12
  2. With PHP 8.1
  3. Install mailchimp module
  4. Configure mailchimp module
  5. Enable 'Enable connected site' - but without connecting this site to Mailchimp first!
  6. When viewing any page the warning will be displayed.

Proposed resolution

Check if $connected_site_paths is not null before testing the paths.

Comments

3li created an issue. See original summary.

3li’s picture

Status: Active » Needs review
StatusFileSize
new869 bytes
bruno.bicudo’s picture

I'll review this one.

bruno.bicudo’s picture

Status: Needs review » Reviewed & tested by the community

Looks good for me. I ran automated tests and also tested it manually, and so far so good, no more errors.

Moving to RTBC.

simgui8’s picture

#2 fixes this deprecation warning for php8.1

Thanks!

avpaderno’s picture

Title: Deprecated function: preg_quote(): Passing null to parameter #1 ($str) of type string is deprecated » preg_quote(): Passing null to parameter #1 ($str) of type string is deprecated
tjtj’s picture

This patch does not apply to my mailchimp module.
I have

function mailchimp_page_bottom(array &$page_bottom) {
  $config = \Drupal::config('mailchimp.settings');

  // Insert JavaScript for Mailchimp Connected Sites, if enabled.
  if (!empty($config->get('enable_connected'))) {
    // Limit JavaScript embed to pre-configured paths.
    $connected_site_paths = $config->get('connected_paths');
    $valid_paths = explode("\r\n", $connected_site_paths);

    $path = \Drupal::service('path.current')->getPath();
    $path = str_replace('/', '', $path);

    if ((\Drupal::service('path.matcher')->isFrontPage() && in_array('<front>', $valid_paths)) || in_array($path, $valid_paths)) {
      $connected_site_id = $config->get('connected_id');

      if (!empty($connected_site_id)) {
        try {
          /* @var \Mailchimp\MailchimpConnectedSites $mc_connected */
          $mc_connected = mailchimp_get_api_object('MailchimpConnectedSites');

          // Verify Connected Site exists on the Mailchimp side and insert JS.
          $connected_site = $mc_connected->getConnectedSite($connected_site_id);
          if (!empty($connected_site)) {

            $mcjs = [

Please update the module so composer can fix this.

poker10’s picture

This patch is created for the 2.x version of the module (not 8.x-1.x).

stijnhau’s picture

Can this patch be merged in?
It works.

  • aprice42 committed 3310720b on 2.x authored by 3li
    Issue #3279948 by 3li, bruno.bicudo, simgui8, apaderno, tjtj, stijnhau,...
aprice42’s picture

Merged into 2.x and will be part of the next release coming later this week!

aprice42’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.