I have a good amount of experience with D7 but not much with D8, so I'm wondering about the "proper" D8 way of doing things here.
So I've got ModuleA and ModuleB
ModuleB depends on ModuleA.
I need to call a function from ModuleA inside of ModuleB.
In D7, this was done by module_load_include(), and D8 appears to have both this function as well as the ModuleHandler class.
I am trying to instantiate this class and use the load method, but it is throwing an error because I am passing nothing to the constructor:
$module_handler = new \Drupal\Core\Extension\ModuleHandler; $module_handler->load('ilib_connect');
TypeError: Argument 3 passed to Drupal\Core\Extension\ModuleHandler::__construct() must implement interface Drupal\Core\Cache\CacheBackendInterface, none given, called in /var/www/company/web/modules/custom/ilib_sso/ilib_sso.module on line 31 in Drupal\Core\Extension\ModuleHandler->__construct() (line 109 of core/lib/Drupal/Core/Extension/ModuleHandler.php).
So I'm not passing anything currently to the constructor (not sure what precisely to pass), and calling the method statically is not a problem, because the load() method references its object and thus causes this error:
Error: Using $this when not in object context in Drupal\Core\Extension\ModuleHandler::load() (line 122 of core/lib/Drupal/Core/Extension/ModuleHandler.php).
So how am I supposed to use this particular class? Or should I just use module_load_include()?
What is the Drupal 8 way of doing things?