How can I get a custom module's file path in a preprocess function? I've got default images located in a custom module directory and I'd like to load them using hook_preprocess_node(). I then will pass the images to the template file.
In the screenshot, I'm loading an image into $default_image, which renders correctly when passed to the template file.
Instead of loading the image from an entity field, I want to read the image directly from the directory in the custom module. Clearly, the path I manually built into $premier_tech_image is incorrect.



The problem is NOT how to access the file. For example, we use code like this for JSON feeds.
$module_handler = $this-&gt;moduleHandler;
$module_path = $module_handler-&gt;getModule('my_custom_module')-&gt;getPath();
$resource = $module_path . '/resources/countries.json';

How do I correctly pass the reference to an image located in the directory of a custom module to the template file?
A Drupal URI starts with a stream wrapper like &quot;public://&quot; that indicates to Drupal how to handle that resource. Typically, the &quot;public&quot; stream wrapper is defined as &quot;treat this resource as a local file within sites/default/files.&quot;
Your module assets are not located within sites/default/files, so they cannot use the &quot;public&quot; stream wrapper.
Drupal doesn't actually come out-of-the-box with a registered stream wrapper for module or theme assets. You might try installing https://www.drupal.org/project/system_stream_wrapper, which would then allow you to make a URI like module://tableau_partners_sync/images/premier-technology.png.