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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

shafiqhossain created an issue. See original summary.

shafiqhossain’s picture

Title: Drupal 8: The “boolean_checkbox” plugin does not exist » Drupal 8: You have requested a non-existent service "router.route_provider.old"
Issue summary: View changes
shafiqhossain’s picture

I checked in core.services.yml file, there is no route declared as "router.route_provider.old"

shafiqhossain’s picture

I 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.

dawehner’s picture

Component: plugin system » extension system

Thank 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.

shafiqhossain’s picture

Here is my hook_install() function. Its creating 2 terms and clear the cache, that's all.

function adplus_install() {
  $locations = ['Front', 'Inner']; // List of ad location
  foreach ($locations as $location) {
    $term = \Drupal\taxonomy\Entity\Term::create([
      	'vid' => 'adplus_ad_location',
      	'name' => $location,
	  	'parent' => array(),
    ]);
    $term->save();
  }
  
  //clear all caches
  drupal_flush_all_caches();
}

Is clearing the cache creating the issue ?

dawehner’s picture

Status: Active » Needs review
FileSize
1.1 KB

@shafiqhossain
Yeah this probably causes the issue.

Do you mind trying out the patch from below? It should fix the issue, ideally.

shafiqhossain’s picture

Yes the patch working well and fixes the issue. Thank you.

alexpott’s picture

@shafiqhossain - you shouldn't be clearing the cache like that during a module install though. It's just not necessary.

shafiqhossain’s picture

Unless 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.

dawehner’s picture

@shafiqhossain
Do you mind uploading the entire module? This would be super helpful for debugging reasons.

shafiqhossain’s picture

thursday_bw’s picture

Status: Needs review » Reviewed & tested by the community

Had the same issue when calling \Drupal::service('module_installer')->uninstall(['search']); uninstall from hook_install()

patch #7 does the trick.. Looks like a simple fix.

dawehner’s picture

IMHO it should be possible to write a test for that.

catch’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

Yes it should.

fizk’s picture

I just ran into this as well. I was trying to uninstall the Drupal-core Search module in hook_install():

<?php

/**
 * Implements hook_install().
 */
function mymodule_install() {
  // Disable Drupal-core Search module.
  if (\Drupal::moduleHandler()->moduleExists('search')) {
    \Drupal::service('module_installer')->uninstall(['search']);
  }
}
Web-Beest’s picture

I 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.

kamkejj’s picture

Also ran into this on 8.3.x with a install profile that's enabling modules in the .install file. The patch did work.

EclipseGc’s picture

Issue tags: -Plugin system

Not plugin related

slydevil’s picture

Patch from #7 works for me as well.

phjou’s picture

The patch #7 is working for me too.

timodwhit’s picture

Version: 8.1.8 » 5.x-dev

Just had to apply patch with the 8.4.5 update. Bumping version #

timodwhit’s picture

Status: Needs work » Needs review
alexpott’s picture

Version: 5.x-dev » 8.6.x-dev

Setting to correct core version.

alexpott’s picture

alexpott’s picture

@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.

The last submitted patch, 25: 2788087-24.test-only.patch, failed testing. View results

TR’s picture

Status: Needs review » Reviewed & tested by the community

Nice. 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.

dawehner’s picture

Issue tags: -Needs tests
alexpott’s picture

Noticed a comment length issue.

  • catch committed 7d18acf on 8.6.x
    Issue #2788087 by alexpott, dawehner, shafiqhossain: Drupal 8: You have...
catch’s picture

Version: 8.6.x-dev » 8.5.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Committed 7d18acf and pushed to 8.6.x. Thanks!

Moving to 8.5.x for backport once 8.5.0 is out.

  • catch committed 8f40d97 on 8.5.x
    Issue #2788087 by alexpott, dawehner, shafiqhossain: Drupal 8: You have...
catch’s picture

Status: Patch (to be ported) » Fixed

Forgot we'd decided on normal patch release rules during RC, so this is fine for 8.5.0, cherry-picked the commit.

Status: Fixed » Closed (fixed)

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