Skip to main content
2 of 10
edited tags
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

Drupal 8 Module layout best practice

I am trying to get to grips with Drupal 8s layout and and architecture.

Having worked with Drupal 6 for the last 2 years I have become used to its procedural style, so I am finding the OOP approach takes a little getting used to.

This is what Im trying to achieve.

My Module has a block which displays content The content of that block is refreshed every 5 seconds This is done with an Ajax call to the server which overwrites the content of the block with the freshly acquired Ajax HTML

So I have gotten the block to display my content on the page easily enough. My problem is now how do I get to the content to refresh. The logic for building the content is contained in functions in my Block class.

I have tried to set up a route in my .yml file to call these functions again to refresh my content via ajax, but I get fatal errors, and also it does not feel like the right approach to access my block class. I feel I should be routing to the controller.

but then, how do I get at the functions that I have written to build the content for the block in the first place?

Should I have written all my logic in my Controller? and if so, how do I access it from my block?