Problem/Motivation

Deleting the system.site:page.front config results in a PHP deprecation.

Deprecated function: preg_quote(): Passing null to parameter #1 ($str) of type string is deprecated in Drupal\Core\Path\PathMatcher->matchPath() (line 80 of core/lib/Drupal/Core/Path/PathMatcher.php).

It also causes a fatal error on the Basic Site Settings form which is where you set the frontpage, meaning it's impossible to fix this error via the UI once it happens.

InvalidArgumentException: Source path has to start with a slash. in Drupal\path_alias\AliasManager->getAliasByPath() (line 110 of core/modules/path_alias/src/AliasManager.php). 

Steps to reproduce

1. Install standard profile
2. Run drush cedit system.site
3. Delete the page.front entry and save
4. Reload the homepage

Proposed resolution

Perhaps just $this->frontPage = $this->configFactory->get('system.site') ->get('page.front') ?? '';

Remaining tasks

Add tests

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

Issue fork drupal-3327662

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

tjtj created an issue. See original summary.

cilefen’s picture

Status: Active » Postponed (maintainer needs more info)
Issue tags: +Needs steps to reproduce

Drupal Core 9 does not have a PHP module.

tjtj’s picture

Status: Postponed (maintainer needs more info) » Active

I picked that because the offending file was .php. Please move it to proper part of core.

cilefen’s picture

Component: php.module » base system
Status: Active » Postponed (maintainer needs more info)

Please let us know the steps to reproduce.

cilefen’s picture

A stack trace would probably help.

tjtj’s picture

Component: base system » php.module
Status: Postponed (maintainer needs more info) » Active

how do I do a stack trace?

cilefen’s picture

Component: php.module » base system
Status: Active » Postponed (maintainer needs more info)

Configure it at admin/config/development/logging. Let's leave the issue metadata alone for now until there is a way to reproduce this bug.

tjtj’s picture

Component: base system » php.module
Status: Postponed (maintainer needs more info) » Active

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/development/logging', NULL) (Line: 1425)
mailchimp_page_bottom(Array) (Line: 360)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}(Object, 'mailchimp') (Line: 405)
Drupal\Core\Extension\ModuleHandler->invokeAllWith('page_bottom', Object) (Line: 361)
Drupal\Core\Render\MainContent\HtmlRenderer->buildPageTopAndBottom(Array) (Line: 150)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 174)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 50)
Drupal\ban\BanMiddleware->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 707)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

cilefen’s picture

sourav_paul’s picture

Version: 9.5.x-dev » 10.0.x-dev
Status: Closed (duplicate) » Active

I also getting the same issue in Drupal 10.0.8.

prabuela’s picture

Assigned: Unassigned » prabuela
StatusFileSize
new823 bytes

Hi @All,

I am not sure this patch will resolve the issue.
The issue is because of passing empty string in preg_quote()

prabuela’s picture

Assigned: prabuela » Unassigned
cilefen’s picture

Status: Active » Postponed (maintainer needs more info)
aurbain25’s picture

aurbain25’s picture

StatusFileSize
new1.86 KB
sir_squall’s picture

Hi,

i just tested the patch for 10.2.0 and 10.2.1 and it's working well.

Thanks

diddism’s picture

Patch doesn't work if system.site page.front is null. I don't know what lead to the circumstance it was null in my case, i suspect config_filter/config_ignore, but it was. Solved it by doing drush cset system.site page.front /node. this means $this->getFrontPagePath() doesn't always return a string.

getFrontpagePath could return $this->frontPage ?? ''; would be a solution I guess.

Version: 10.0.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Component: php.module » base system
Issue tags: +Bug Smash Initiative

This issue is filed against a component that has been removed from Drupal core a long time ago and thus is not seen by the community. I am changing the component.

Steps to reproduce were asked for 2 years ago and they have not been supplied. What is needed is how to recreated the problem from a fresh install of Drupal 10 or 11.

Since we need more information to move forward with this issue, I am keeping the status at Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

Thanks!

sir_squall’s picture

I still got this error, when we are using the :
$node = \Drupal::routeMatch()->getParameter('node');

in this hook:
_preprocess_html(&$variables) {

we have this preg_quote error

b.khouy’s picture

This issue stems from the use of $this->getFrontPagePath() as the first parameter of the preg_quote() function in web/core/lib/Drupal/Core/Path/PathMatcher::matchPath method. We need to ensure that the first argument is always a string. In the attached patch, I’ve added a check to validate the returned value accordingly

b.khouy’s picture

Status: Postponed (maintainer needs more info) » Needs review
smustgrave’s picture

Status: Needs review » Postponed (maintainer needs more info)

Fixes should be in MRs

Issue summary should be updated with reliable steps to reproduce (moving to PNMI for that)

Also rest of sections should be filled in

Possibly will need test coverage.

sir_squall’s picture

I still have the Deprecated function: preg_quote(): Passing null to parameter

cilefen’s picture

@sir_squall: This issue needs to be updated as specified in comment 23. Anything you can do on that end will help this to be solved.

sir_squall’s picture

I found another thread with a Similar issue:
https://www.drupal.org/project/domain/issues/3295160

I don't know how to do the MRs..

cilefen’s picture

That’s ok. There are other issue updates needed besides code.

kevinquillen’s picture

I was able to trigger this in a simple kernel test where I want to check that some custom entity routes are marked as admin.


/**
 * Tests the EntityAdminHtmlRouteProvider.
 */
class EntityAdminHtmlRouteProviderTest extends KernelTestBase {

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'mymodule',
    'domain',
    'node',
    'text',
    'user',
    'system',
  ];

  /**
   * The entity type manager service.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected EntityTypeManagerInterface $entityTypeManager;

  /**
   * @var \Drupal\Core\Routing\AccessAwareRouter
   */
  protected AccessAwareRouter $router;

  /**
   * {@inheritdoc}
   */
  protected function setUp(): void {
    parent::setUp();
    $this->installEntitySchema('mymodule');
    $this->installSchema('system', ['sequences']);
    $this->entityTypeManager = $this->container->get('entity_type.manager');
    $this->router = $this->container->get('router');
  }

  /**
   * Tests if the canonical route is correctly configured.
   */
  public function testCanonicalRoute(): void {
    $collection = $this->router->getRouteCollection();
    $route = $collection->get('entity.mymodule_entity.canonical');
    $this->assertTrue($route->getOption('_admin_route'), 'The route is marked as an admin route.');
  }

}

The test passes, but is marked with a deprecation. Not sure how to get around it.

kevinquillen’s picture

I reconfigured the test to not rely on a custom module that also required Domain (for the domain.negotiator service in one of its classes) and this issue went away. It must be something in Domain module and similar modules that rely on core/lib/Drupal/Core/Path/PathMatcher::matchPath.

david_neil_smith’s picture

Hello all. I was a Windows programmer but never a website/php one and have successfully used Drupal functionality for many years.
However, the charity of which I'm a member has a free account with Krystal who are very helpful - but they're not developers. We needed to upgrade our old Drupal 9 site so I deleted the old installation and installed, using a Softaculous script, a new version 11.x. It seemed to go well apart from an error re 'trusted_host_patterns' - which I managed to fix.

However, trying to access Basic Site Settings to set things like the home page produces the error "The website encountered an unexpected error. Try again later." and the log file shows "Deprecated function: preg_quote(): Passing null to parameter #1 ($str) of type string is deprecated in Drupal\Core\Path\PathMatcher->matchPath()"

The team at Krystal Hosting installed version 10.4.6 in a 'subdirectory' and that did not display the same error so I deleted the 11.x install and installed 10.4.6 using a different Softaculous script. This produced the same 'trusted_host_patterns' error and the same error when trying to access Basic Site Settings.

This is how I've ended up here posting this message. With being no PHP or Drupal developer I am at a loss to work out what is wrong and, more importantly, how to fix it. So it works in a subdirectory but not when at the actual website.

Please can anyone suggest some solution as I am at a complete loss.
Many thanks in anticipation of your help.

David

smustgrave’s picture

Should this be moved back to NW if someone can add steps.

acbramley’s picture

Issue summary: View changes
Status: Postponed (maintainer needs more info) » Active
Issue tags: -Needs steps to reproduce

This is pretty easy to reproduce, adding to the IS.

If anyone is facing this issue, setting the page.front config key in system.site configuration should fix it. You may have to use drush to do this by using drush cedit system.site and adding a front key under page, or update your exported config directly. The UI doesn't seem to be functional when this happens.

Hiding the patches, work will need to be pushed to a new MR.

acbramley’s picture

Issue summary: View changes
Status: Active » Needs work
Issue tags: +Needs tests
acbramley’s picture

Issue summary: View changes
acbramley’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
smustgrave’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Test-only coverage can be found here https://git.drupalcode.org/issue/drupal-3327662/-/jobs/7523684

Solution seems straight forward enough and don't see any issue.

acbramley’s picture

Title: Deprecated function: preg_quote(): Passing null to parameter #1 ($str) » Deleting the system.site:page.front config results in a PHP deprecation

Updating title

longwave’s picture

Version: 11.x-dev » 10.6.x-dev
Status: Reviewed & tested by the community » Fixed

Backported down to 10.6.x as an eligible bug fix.

Committed and pushed 675ec8e209f to main and f6154ecc5a7 to 11.x and 76b064e83ce to 11.3.x and 867fd8e8e28 to 10.6.x. Thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • longwave committed 867fd8e8 on 10.6.x
    fix: #3327662 Deleting the system.site:page.front config results in a...

  • longwave committed 76b064e8 on 11.3.x
    fix: #3327662 Deleting the system.site:page.front config results in a...

  • longwave committed f6154ecc on 11.x
    fix: #3327662 Deleting the system.site:page.front config results in a...

  • longwave committed 675ec8e2 on main
    fix: #3327662 Deleting the system.site:page.front config results in a...

Status: Fixed » Closed (fixed)

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