I am creating two custom content type with reference to these pages:
https://www.drupal.org/node/2629550
https://www.drupal.org/node/2693979
Everything works fine. Content type with fields is created. But While installing, it throws an exception and as a result hook_install is not executing, i think. The error is as follows:
Uncaught PHP Exception Symfony\\Component\\DependencyInjection\\Exception\\ServiceNotFoundException: "You have requested a non-existent service "router.route_provider.old". Did you mean one of these: "router.route_provider", "router.route_preloader"?" at ...\\core\\lib\\Drupal\\Component\\DependencyInjection\\Container.php line 157
Could anyone please help me, why this is happening and how to fix it ?
I am using Drupal 8.1.8 version.
Comment | File | Size | Author |
---|---|---|---|
#30 | 2788087-30.patch | 2.66 KB | alexpott |
#30 | 25-30-interdiff.txt | 856 bytes | alexpott |
#25 | 2788087-24.patch | 2.66 KB | alexpott |
#25 | 2788087-24.test-only.patch | 1.53 KB | alexpott |
#7 | 2788087-7.patch | 1.1 KB | dawehner |
Comments
Comment #2
shafiqhossain CreditAttribution: shafiqhossain commentedComment #3
shafiqhossain CreditAttribution: shafiqhossain commentedI checked in core.services.yml file, there is no route declared as "router.route_provider.old"
Comment #4
shafiqhossain CreditAttribution: shafiqhossain commentedI have created a router names as "router.route_provider.old" by copying "router.route_provider" in the core.services.yml file, which solves my problem.
i think Drupal uses "router.route_provider.old" router as a temporary to copy "router.route_provider" router info. But as this router name is not exists, its throwing exception.
I don't know if this is a bug or there is better way to fix it.
Comment #5
dawehnerThank you for reporting this issue. This is certainly interesting
Can you show your exact code you try to use? In theory the router.route_provider.old should be always available, but well, maybe you cause a container rebuild in your
hook_install()
code which could cause this issue.Comment #6
shafiqhossain CreditAttribution: shafiqhossain commentedHere is my hook_install() function. Its creating 2 terms and clear the cache, that's all.
Is clearing the cache creating the issue ?
Comment #7
dawehner@shafiqhossain
Yeah this probably causes the issue.
Do you mind trying out the patch from below? It should fix the issue, ideally.
Comment #8
shafiqhossain CreditAttribution: shafiqhossain commentedYes the patch working well and fixes the issue. Thank you.
Comment #9
alexpott@shafiqhossain - you shouldn't be clearing the cache like that during a module install though. It's just not necessary.
Comment #10
shafiqhossain CreditAttribution: shafiqhossain commentedUnless I clear the cache after installation, my new content types are not displaying in the content type list. In order to see the new content types in the list, I have to manually clear the cache from Performance page.
Comment #11
dawehner@shafiqhossain
Do you mind uploading the entire module? This would be super helpful for debugging reasons.
Comment #12
shafiqhossain CreditAttribution: shafiqhossain commentedIts here:
https://github.com/shafiqhossain/adplus
Comment #13
thursday_bw CreditAttribution: thursday_bw at Catalyst IT commentedHad the same issue when calling
\Drupal::service('module_installer')->uninstall(['search']);
uninstall fromhook_install()
patch #7 does the trick.. Looks like a simple fix.
Comment #14
dawehnerIMHO it should be possible to write a test for that.
Comment #15
catchYes it should.
Comment #16
fizk CreditAttribution: fizk commentedI just ran into this as well. I was trying to uninstall the Drupal-core Search module in
hook_install()
:Comment #17
Web-BeestI ran into this issue (Drupal 8.3.1) as well.
I have a hook_install that disables another modules which generated the error.
I can confirm this patch works for me.
Comment #18
kamkejj CreditAttribution: kamkejj as a volunteer commentedAlso ran into this on 8.3.x with a install profile that's enabling modules in the .install file. The patch did work.
Comment #19
EclipseGc CreditAttribution: EclipseGc at Acquia commentedNot plugin related
Comment #20
slydevil CreditAttribution: slydevil commentedPatch from #7 works for me as well.
Comment #21
phjouThe patch #7 is working for me too.
Comment #22
timodwhit CreditAttribution: timodwhit commentedJust had to apply patch with the 8.4.5 update. Bumping version #
Comment #23
timodwhit CreditAttribution: timodwhit commentedComment #24
alexpottSetting to correct core version.
Comment #25
alexpottHere's a test.
Comment #26
alexpott@shafiqhossain I cannot reproduce the behaviour of the content type list not being updated after install when node types are created. I've tested both with node_test_config and your module. As stated before called drupal_flush_all_caches() during a module install is not recommended.
Comment #28
TR CreditAttribution: TR commentedNice. The test reproduces the error, and the patch solves the problem.
I have encountered this several times in core 8.4.x and 8.5.x, and now 8.6.x. I can't work around it in my own code because it is being caused by my module's dependencies.
I have been using the patch in #7 for about four months now and it has solved the problem.
Comment #29
dawehnerComment #30
alexpottNoticed a comment length issue.
Comment #32
catchCommitted 7d18acf and pushed to 8.6.x. Thanks!
Moving to 8.5.x for backport once 8.5.0 is out.
Comment #34
catchForgot we'd decided on normal patch release rules during RC, so this is fine for 8.5.0, cherry-picked the commit.