Problem/Motivation
/**
* Prepare the kernel for handling a request without handling the request.
[..]
* @deprecated in Drupal 8.0.x and will be removed before 9.0.0. Only used by
* legacy front-controller scripts.
*/
The one line summary is not useful information, and the deprecation message is not true (which is kind of hilarious: #2556273-4: Fix @deprecation docs of Drupal\Core\DrupalKernelInterface::prepareLegacyRequest())
prepareLegacyRequest() is used extensively by the testing system.
It's also used by drupal_install_system() and drupal_rebuild().
Found 13 matches of prepareLegacyRequest in 11 files.
authorize.php
$kernel->prepareLegacyRequest($request); [position 68:12]
install.core.inc
// \Drupal\Core\DrupalKernel::prepareLegacyRequest() since normal routing [position 474:33]
install.inc
$kernel->prepareLegacyRequest($request); [position 619:12]
utility.inc
$kernel->prepareLegacyRequest($request); [position 43:12]
DrupalKernel.php
public function prepareLegacyRequest(Request $request) { [position 707:19]
DrupalKernelInterface.php
public function prepareLegacyRequest(Request $request); [position 128:19]
FunctionalTestSetupTrait.php
$this->kernel->prepareLegacyRequest($request); [position 389:20]
$this->kernel->prepareLegacyRequest(\Drupal::request()); [position 442:20]
// DrupalKernel::prepareLegacyRequest() -> DrupalKernel::boot() but that [position 446:24]
InstallerTestBase.php
$this->kernel->prepareLegacyRequest($request); [position 151:22]
run-tests.sh
$kernel->prepareLegacyRequest($request); [position 58:12]
KernelTestBase.php
$kernel->prepareLegacyRequest($request); [position 369:14]
BrowserTestBase.php
$kernel->prepareLegacyRequest($request); [position 1019:14]
Proposed resolution
Remove the usages and replace them with calls to DrupalKernel::boot() and DrupalKernel::preHandle().
Remaining tasks
User interface changes
API changes
Data model changes
Comments
Comment #2
mile23Comment #4
mile23Curious what this tells us.
Comment #6
mile23Some work on this. WIP.
Comment #8
mile23Getting closer. I'm not clear on why half of these occurrences are there instead of
boot()andpreHandle(). This whole system needs clean up.Also not clear on why
preHandle()isn't part ofboot()orhandle(), but that's out of scope here.Comment #10
mile23Your moment of zen:
(Answer: The strings have HTML tags in them which were stripped for display.)
Comment #11
mile23More work...
Comment #13
mile23Another try. This looks pretty complete.
I would love to be able to test
run-tests.shbut I can't.Comment #17
berdirDoesn't apply anymore.
Comment #18
mile23Reroll.
Comment #20
mile23Fixing usages in
Drupal\FunctionalTests\Installer\InstallerTestBaseand\Drupal\TestSite\Commands\TestSiteUserLoginCommand.There's also a @todo in
FunctionalTestSetupTrait::rebuildAll()that will need some attention. Calling it a follow-up for now.Comment #21
alexpottThe pushing the request onto the stack is done in preHandle() already :) So we could move the request setting stuff above $kernel->preHandle().
Also we should see how much of this is really needed.
__NAMESPACE__ . '\DrupalKernel::prepareLegacyRequest...'is the usual construction for this.booting and then rebuilding feels really odd - I'm sure this can be done in a more optimal way.
Let's move these above the preHandle and then we can remove the push to the stack.
Comment #22
alexpottI've tried to address #21. Things might break.
Comment #23
alexpottLet's add some test coverage because we can.
Comment #24
alexpottAt the moment in kernel tests the request stack has 3 requests (all the same mind you). But that seems worth testing that we don't mess that up again.
The interdiff is the test only patch.
Comment #26
mile23That pretty much sums up the scope of the issue. :-)
It would be great if we could expand this documentation a little, so we know why a
preHandle()is necessary and why it's separate fromhandle(). Otherwise it still kind of looks a lot likeprepareLegacyRequest().I don't see where
$modules_enabledis coming from.Comment #27
alexpottI don't think it's the job of this issue to do add documentation to DrupalKernel::preHandle() - also the situations where we are calling it are not really to be duplicated in contrib or anywhere. Usually preHandle() is called by part of the handle() - ie. by \Drupal\Core\StackMiddleware\KernelPreHandle - as that class says it's really about preparing the environment if page caching as not kicked in.
Nice spot on the copy pasta. Fix in the patch.
Comment #28
andypostThis request manipulations reminds me about related #2613044: Requests are pushed onto the request stack twice, popped once
Comment #29
jibranhttps://gitlab.com/weitzman/drupal-test-traits/blob/master/src/DrupalTra... needs an update as well after this.
Comment #30
jibranhttps://github.com/drush-ops/drush/blob/master/src/Boot/DrupalBoot8.php#... is another one.
Comment #31
alexpott@jibran both of them already need an update. This is not deprecating the method. It already is deprecated.
Comment #32
wim leers#28 hah I came here too to point to #2613044: Requests are pushed onto the request stack twice, popped once :)
This is the only push/pop-related change and definitely won't fix #2613044: Requests are pushed onto the request stack twice, popped once. I was sneakily hoping this would also fix #2613044…
Comment #33
moshe weitzman commentedThis method may already be deprecated, but it was never clear how to replace it. This patch answers that question - thanks. I will update both Drush and DTT accordingly.
Comment #34
moshe weitzman commentedDrush and Drupal Test Traits have both been updated for this change. Releases will come soonish.
Comment #35
volegerDeprecation message needs to be updated regarding CS
Comment #36
mikelutzupdating deprecations, adding a quick CR.
Comment #37
lendudeUpdated the IS with the current fix.
This looks ready to me, all feedback has been addressed and all tests are green.
Comment #38
wim leers@moshe weitzman++ for updating Drush & Drupal Test Traits!
And yay for RTBC! #24 added explicit backwards compatibility test coverage. I was first confused by all the
lines, but that's what the deprecated method used to do. So this makes sense.
This was the reason #20 added a
Needs followupissue tag, and since this line is still there, we still need that follow-up.Comment #39
larowlanI wonder whether we could put this in Kernel::preHandle - it feels like knowledge that outside consumers should not need to know
Let's see whether that's do-able
If this works, our recommended approach would just be
->boot()->preHandle($request)because of chainingComment #40
mile23The idea of
preHandle()seems to fall into that category, too. That's why I wanted to update the docblocks in #26.Comment #41
larowlanAdded #3074414: Expand documentation of DrupalKernel::preHandle to indicate when it should be used, and when ::handle() is a better option for that, I agree - we should make it clear when to use what
Comment #43
larowlanGuess not, back to RTBC for the patch at #36
Comment #44
larowlanComment #45
larowlanCommitted the patch at #36
Committed 8181767 and pushed to 8.8.x. Thanks!
Comment #48
quietone commentedPublished change record
Comment #49
andypostCreated 11.x follow-up to #3453216: Clean up outdated mentions of prepareLegacyRequest