2

I've read about the Basic Structure guide to building a Drupal 8 module. It's great that it outlines the basic files needed to get a module up and running.

Where it falls short is the contents of the src folder.

I've seen modules with the usual folders like src/Access, src/Plugins, src/Form. But I've also seen ones that appear to be arbitrarily named. Some files are referenced in annotations and yaml config, while some Drupal magically just knows about without some reference.

Does the folder structure matter? Does Drupal care if I put controllers in src/MaybeNotControllers? Are plugins like, formatters and widgets, still discoverable if not put in src/Plugins? Is there a definitive guide to what files go where and how Drupal finds out about them?

closed as too broad by leymannx, mradcliffe, Jdrupal, kiamlaluno Aug 19 at 10:42

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 6
    It's reeeeally hard to answer this exhaustively. The folder structure matters insofar as it needs to match namespaces for autoloading purposes. For the majority of real world usages the structure itself is arbitrary, but there are some conventions, and also exceptions. Plugins are one of the exceptions, as are entities and other annotated things. Controllers and forms tend to be conventionally located, but because they're most often referred to explicitly (e.g. explicitly setting the form or controller for a route), they don't have to be. – Clive Aug 16 at 12:41
  • 5
    Yes, plugins (entities are also plugins) are the exception. @Joseph, you find more infos in the docs drupal.org/docs/8/api/plugin-api/annotations-based-plugins – 4k4 Aug 16 at 13:06
  • For convention, there is not much need to name "Controllers" to something else - particularly if this code is contributed back out in some way. – Kevin Aug 16 at 15:11

Browse other questions tagged or ask your own question.