Problem/Motivation
The global variables base_url
, base_path
and base_root
as well as the base_path()
function are still used throughout core. Removal of those is tricky, since there is no direct replacement on the Symfony request object for those. The globals in Drupal are always relative to the application directory, while Symfony $request->getBaseUrl()
returns the base URL relative to the front controller.
For example when running the installer (hxxp://example.com/drupal/core/install.php), Symfony will report the base URL including the core
path, while $base_url
will only be up to drupal
.
Proposed resolution
Since there is no direct replacement in Symfony, it is necessary to introduce an additional service which is capable of returning the base URL and the base path relative to the application (not the front controller).
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|
Issue fork drupal-2529170
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
Comment #1
znerol CreditAttribution: znerol commented\Drupal\Core\App
is probably not the best place to add this, any ideas?Comment #3
znerol CreditAttribution: znerol commentedComment #5
znerol CreditAttribution: znerol commentedProper patch.
Comment #7
znerol CreditAttribution: znerol commentedFix unit test.
Comment #9
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commented#1: Drupal\Core\Site might work.
Other idea:
Drupal\Core\Utility
Or just inject as a \SplString from DrupalKernel like app.root.
Comment #10
znerol CreditAttribution: znerol commentedI'm currently struggling with reproducing the failures. I suspect there is something going on with run-tests.sh here. I suspect some issue with
SCRIPT_FILENAME
(should be absolute and seems to be the same asSCRIPT_NAME
).Comment #11
larowlanAre you running from a sub directory locally? bot does
Comment #12
znerol CreditAttribution: znerol commentedYes. I was not able to reproduce the fails in the installer, but a closer look at the others revealed some problems with the patch. E.g.
base_path
is expected to end with a/
Comment #15
dawehner-1 to put it into utility, given that its kinda a dumping ground for everything.
I think Site is totally fine, as similar to Settings() it depends on the loaded multi site environment.
We should explain exactly here what which bit is.
Comment #16
znerol CreditAttribution: znerol commentedFixes the
LanguageNegotiationUrlTest
and also #2481833: Remove LanguageNegotiationUrl's usage of base_path().Comment #17
znerol CreditAttribution: znerol commentedFix
MailFormatHelper
.Comment #20
znerol CreditAttribution: znerol commentedFix
UrlRewritingTest
:base_path()
always returns a string which is terminated by a slash. Therefore appending a path separator to the return value is plain wrong. (i.e. tests are wrong in head but they pass nevertheless becausefile_test_file_url_alter
is wrong as well.SCRIPT_NAME
andSCRIPT_FILENAME
server superglobal.Comment #22
znerol CreditAttribution: znerol commentedFix
PathProcessorTest
.Comment #23
znerol CreditAttribution: znerol commentedThe difference in test results (Installer) between testbot and DCI is interesting. I may have found the culprit: Tests pass for me locally if APCu is disabled and I get the same exceptions (hash salt not defined) when APCu is enabled.
Seems like there is no APCu on DrupalCI?
Comment #25
znerol CreditAttribution: znerol commentedOh, there is. I'm really lost now regarding the installer tests and I do not manage to reproduce them neither. Any ideas?
Comment #26
znerol CreditAttribution: znerol commentedThis was quite a hard because of #2507831: Harden redirect responses to make external URIs opt in (was SA-CORE-2015-002 foward-port) relying on
RequestContext::getCompleteUrl()
.Comment #28
znerol CreditAttribution: znerol commentedComment #30
znerol CreditAttribution: znerol commentedAttempting to understand what is going wrong in testbot by adding
debug()
to\Drupal\Component\Utility\OpCodeCache
.Comment #31
znerol CreditAttribution: znerol commentedComment #33
mpdonadioDon't we just need a version of \Drupal\Core\Routing\RequestContext that uses the application context and not the current request context, and then inject that where it is needed (mainly the link generator)?
Comment #34
mpdonadioReroll b/c #2521852: Make it possible to use your own exception handler
Just used the hunk from HEAD in the conflict in DrupalKernel::handleException().
Comment #35
mpdonadioSetting status so these can fail properly...
Comment #38
mpdonadioSpent some time with this today. The patch is failing because the installer is really broken. Most of the URLs for JS, CSS, etc, have 'core/core' in the paths. *REDACTED*. May look into this later tonight, but may not have time.
Comment #39
mpdonadioThe interactive installer was broken (on my machine at least) because of some screwiness with the script name and symlinks between where Apache had its DOCROOT and where the Drupal installation actually was, which caused App::prepareBasePath() to not work as expected, resulting in general mayhem with paths and requests. Also added a helper to Drupal to get the service so autocomplete in PhpStorm work would, and so I could chase the functions properly... Let's see what this does.
Comment #41
mpdonadioToday I learned that you can't mock methods used in a constructor.
Methinks this will be green. AppTest works locally now.
I also think this could possibly be elevated to a major, because I suspect that it is the best solution for #2548095: Add option to Url() to force the site base_url to be used.
Comment #42
borisson_The patch looks great, this also seems to resolve #2481833: Remove LanguageNegotiationUrl's usage of base_path(), so I closed that issue in favour of this one. I think issue credit might need to be copied over from there though.
Comment #43
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedApologies if this has been asked already:
Why is this necessary?
I thought Symfony had similar logic already in the request object.
Comment #44
znerol CreditAttribution: znerol commented#43 That's what I tried to explain in the issue summary. Symfonys
Request::getBaseX()
is relative to the front controller (i.e., it delivers different results forbase-path/index.php
andbase-path/core/install.php
). That is a problem because Drupal assumes that the base path is relative to the application, not relative to the front controller.Comment #45
hussainwebIt seems this could be very disruptive at this stage.
Comment #47
mpdonadioTried a quick rebase, and there are lots of conflicts here.
Comment #48
deepakaryan1988Working on this!
Comment #49
deepakaryan1988In previous comment, why the above lines has been replaced, I don't understand this, Can someone please help me with this.
As far as I am building new re-rolled patch, I am not including above changed lines.
Comment #50
deepakaryan1988After lots of issues, rerolled #41 patch.
Let's hope it will pass the QA test.
Comment #54
pwolanin CreditAttribution: pwolanin as a volunteer and at SciShield commentedSince we are already extending the request context, can we just put the logic there?
Comment #55
Wim LeersBecause this is not yet fixed, I had to add a hideous work-around to #2830326-5: Broken link to 'Put your site into maintenance mode' on update.php results in WSOD.
Comment #56
vprocessor CreditAttribution: vprocessor at Skilld commentedComment #57
vprocessor CreditAttribution: vprocessor at Skilld commentedrerolled
Comment #60
Mile23Reroll.
DrupalKernel
still has my favorite:DrupalKernel::guessApplicationRoot()
, which should be the job of the app service.Comment #62
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedFixed the PHP error introduced in last patch.
Comment #64
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedComment #70
volegerJust reroll
Comment #76
larowlanTagging with Bug Smash Initiative because this blocks a bug
Comment #77
yogeshmpawarPicking it now.
Comment #78
yogeshmpawarUpdated patch with reroll diff added.
Comment #79
volegerPlease fix PHPCS issues
Comment #80
yogeshmpawaryes working on it.
Comment #81
yogeshmpawarFixed PHPCS issues & hiding #78 patch. Added reroll diff against #70.
Comment #82
daffie CreditAttribution: daffie commentedThis should be changed to using the container parameter "app.root". The code should become like:
arguments: ['%app.root%']
.We are not deprecation the function
base_path()
in this issue. Therefor replacing the function is out of scope for this issue and should not be done in this issue. This is done multiple times in this patch, please remove them all unless we meed to change it anyway for this patch. A followup issue for this should be created.I do not think that this check is necessary. The only thing it that
$this->baseUrl
and$this->basePath
are recalculated.The use of
getMasterRerquest()
is deprecated. Please usegetMainRequest()
.Could we change these lines to:
As this is the way we are doing it in Drupal core. Doing the same way improves readability.
This only works because we are testing with paths that do not have
/./
,/../
and extra/
characters. I am not sure we should add testing for that.We do not have testing for this in Drupal\Tests\Core\AppTest. Please add testing for this.
Contrib or custom code that is relying on these globals to be set will fail when this patch is committed.
We need to add a comment that this lines are a BC layer that will be removed in Drupal 11 with a link to the be created "change record".
Nitpick: Why double "(("? A single one should be enough.
We cannot make this change. If contrib or custom code call this class with the second parameter being the RequestContext a deprecation warning should be trigger. With the change as it now is the code will fail. Please remove the parameter typehint and add a if-statement testing for the instance type. If RequestContext the throw a deprecation warning and the parameter to the correct value.
This is a public method. We cannot just remove it. It needs to be deprecated and when it is used by contrib or custom it should still work. A deprecation warning should be given.
These 3 public method cannot just be remove, they need to be properly deprecated.
We have added a create method to the class, therefor these changes should not be necessary.
Comment #86
volegerRerolled against 10.1.x
Comment #87
daffie CreditAttribution: daffie commentedTestbot is not happy: https://www.drupal.org/pift-ci-job/2504335
Comment #88
andypostMR meeds rebase
Comment #89
volegerComment #90
joseph.olstadTried rebase via the merge request GUI, it fails. Feb 23 status looks green from the above comment description but I don't see the job, not sure where to find it.
Comment #91
andypostChanged properties and fixed last usage, token changes looks like needs discussion
Comment #92
daffie CreditAttribution: daffie commentedThe testbot is not happy
Comment #94
volegerThe issue appears on the Drupal\Tests\Core\Command\QuickStartTest run. It probably blocks the rest of the functional tests.
Any idea what is the cause of that behavior?
Comment #95
volegerComment #96
andypostI guess it means that functional tests does not get request properly so url is not extracted, it reminds me somehow #2484991: Add the session to the request in KernelTestBase, BrowserTestBase, and drush
Comment #97
voleger#2484991: Add the session to the request in KernelTestBase, BrowserTestBase, and drush looks great, let's wait when it will be fixed.