6

I noticed that, in the current page crumb module, there is no .module file.

Why is that no longer necessary? As a test I added a .module file, but it seems it is not being read. Where can I find documentation about using or not using a .module file in Drupal 8?

1 Answer 1

8

.module files are not required if you are not adding any procedural code. If you need to use any hooks, like hook_theme or hook_form_alter, yes, you need to do that in the .module file, because it cannot be done anywhere else. A lot of modules that extend base classes or provide services don't have any need to also include a .module file unless they provide something via hook_help, for example.

Some developers provide empty .module files, like:

<?php

// empty

I simply omit them if they have no code.

And as a test I added a .module file but it seems it is not being read.

You'd have to elaborate on this, because any module that is enabled that has a .module file is definitely read. You may have to clear cache to pick up on changes.

3
  • 1
    yes but i added a module file to test it and it seems to be being bypassed completely. Is there something in the services file that could be making that .module file be bypassed ? services: pup_taxonomy_breadcrumb.breadcrumb: class: Drupal\pup_taxonomy_breadcrumb\BreadcrumbBuilder arguments: ['@router.request_context', '@access_manager', '@router', '@path_processor_manager', '@config.factory', '@title_resolver', '@current_user', '@path.current', '@menu.active_trail', '@plugin.manager.menu.link'] tags: - { name: breadcrumb_builder, priority: 1 }
    – Diana
    Commented Apr 10, 2017 at 17:09
  • They are not related. You need to use some sort of debugging method to ensure the code in the .module file is even being hit to confirm that it is being loaded.
    – Kevin
    Commented Apr 10, 2017 at 17:09
  • you are right I had spelled the name wrong. thanks
    – Diana
    Commented Apr 10, 2017 at 17:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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