1

Im upgrading a D7 module to D8 and it turns out conf_path() is deprecated but I cant find the replacement.

I found a github page that said use this

 DrupalKernel::findSitePath(Request::createFromGlobals())

but I still WSOD when that is called.

  • 1
    Are you importing the right namespaces in your code? Your server logs should contain a more detailed error if you're getting a WSOD – Clive Nov 13 '15 at 22:41
  • Are you using the Drupal Module Upgrader? chances are that it will tell you. – No Sssweat Nov 14 '15 at 4:43
2

One of two change records for conf_path() is Bootstrap refactored to use the kernel. This states that

Note: In D8, instead of using conf_path(), \Drupal\Core\DrupalKernel::getSitePath() instead. If the kernel is unavailable (such as above, where the code shows the booting of the D8 kernel) or the site path needs to be recalculated then Drupal\Core\DrupalKernel::findSitePath() can be used

So if you have access to the DrupalKernel object, then calling getSitePath() on that object will work. This is probably not the case.

However, there is a service for this called site.path that can be injected into a class that you need it. I think the change record could be updated to reference this factory class.

Using the global Drupal object:

$conf_path = \Drupal::service('site.path');
  • I get errors saying 'You have requested a non-existent service "site.path.factory" when using that. – BrandenB171 Nov 18 '15 at 15:36
  • In addition if i use the \Drupal\Core\DrupalKernel::getSitePath() i get an error for calling a non-static method statically – BrandenB171 Nov 18 '15 at 16:13
  • I modified my answer. I forgot that you can jut call "site.path" service and that just calls the factory. – mradcliffe Nov 19 '15 at 17:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.