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
| Comment | File | Size | Author |
|---|
Issue fork drupal-3327662
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:
- 3327662-deprecated-function-pregquote
changes, plain diff MR !13861
Comments
Comment #2
cilefen commentedDrupal Core 9 does not have a PHP module.
Comment #3
tjtj commentedI picked that because the offending file was .php. Please move it to proper part of core.
Comment #4
cilefen commentedPlease let us know the steps to reproduce.
Comment #5
cilefen commentedA stack trace would probably help.
Comment #6
tjtj commentedhow do I do a stack trace?
Comment #7
cilefen commentedConfigure it at admin/config/development/logging. Let's leave the issue metadata alone for now until there is a way to reproduce this bug.
Comment #8
tjtj commentedDeprecated 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)
Comment #9
cilefen commentedComment #10
sourav_paulI also getting the same issue in Drupal 10.0.8.
Comment #11
prabuela commentedHi @All,
I am not sure this patch will resolve the issue.
The issue is because of passing empty string in preg_quote()
Comment #12
prabuela commentedComment #13
cilefen commentedComment #14
aurbain25 commentedComment #15
aurbain25 commentedComment #16
sir_squall commentedHi,
i just tested the patch for 10.2.0 and 10.2.1 and it's working well.
Thanks
Comment #17
diddism commentedPatch 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.
Comment #19
quietone commentedThis 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!
Comment #20
sir_squall commentedI 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
Comment #21
b.khouyThis issue stems from the use of
$this->getFrontPagePath()as the first parameter of thepreg_quote()function inweb/core/lib/Drupal/Core/Path/PathMatcher::matchPathmethod. 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 accordinglyComment #22
b.khouyComment #23
smustgrave commentedFixes 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.
Comment #24
sir_squall commentedI still have the Deprecated function: preg_quote(): Passing null to parameter
Comment #25
cilefen commented@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.
Comment #26
sir_squall commentedI found another thread with a Similar issue:
https://www.drupal.org/project/domain/issues/3295160
I don't know how to do the MRs..
Comment #27
cilefen commentedThat’s ok. There are other issue updates needed besides code.
Comment #28
kevinquillen commentedI was able to trigger this in a simple kernel test where I want to check that some custom entity routes are marked as admin.
The test passes, but is marked with a deprecation. Not sure how to get around it.
Comment #29
kevinquillen commentedI 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.Comment #30
david_neil_smith commentedHello 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
Comment #31
smustgrave commentedShould this be moved back to NW if someone can add steps.
Comment #32
acbramley commentedThis 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.siteand adding afrontkey underpage, 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.
Comment #34
acbramley commentedComment #35
acbramley commentedComment #36
acbramley commentedComment #37
smustgrave commentedTest-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.
Comment #38
acbramley commentedUpdating title
Comment #39
longwaveBackported 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!