0

I'm coming to Drupal from more conventional MVC frameworks (Laravel, CakePHP, etc.)

In those frameworks, if I want a specific element (say, a form) to appear only on specific pages, then I basically do this:

  • First, I register a route which maps a URL pattern (e.g., /path/to/form/page) to a PHP controller method (e.g., FormController::display().
  • Then, from FormController::display(), I return a view which includes the HTML for that form.

Things seem to be very different in Drupal, and it's really confusing me. I think I've figured out how this works in Drupal, maybe – but it's so bizarre (compared to what I'm used to) that part of me thinks it can't possibly be right.

So: can you please confirm (or deny) the following?

In Drupal, I should add all blocks that will ever appear in a particular region (on any URL) to that region (on the Structure > Block Layout page).

I should then configure the Visibility > Pages tab of each block to control which URL(s) it should appear on.

So, for a large site, the "Content" section of my Block Layout page could potentially include dozens of blocks. And it would therefore be misleading to think of the Block Layout view as a preview version of any given page on my site. It's just a listing of which blocks might appear in a region on any given page, depending on how the block placements are configured.

Is that basically right?

5
  • It's basically right. – Jaypan May 15 '20 at 14:57
  • 1
    it would therefore be misleading to think of the Block Layout view as a preview version of any given page on my site Yes ,exactly that - the block layout interface is not intended to represent individual pages – Clive May 15 '20 at 14:57
  • Also worth noting you can do exactly the steps you mentioned at the top of your question (create a controller, route, display something) within Drupal. It sounded like you thought this wasn't possible. drupal.org/docs/8/creating-custom-modules/… – Leigh May 15 '20 at 15:03
  • Yes and no. Blocks is just one concept in Drupal. You could also simply have a content type "Page" and on that page use a custom reference field "Form" to let editors place forms. You could even have a block reference field like the one provided by the Block Field module to let editors place blocks themselves. Or maybe have this block field inside one of many Paragraphs types. Drupal is a Framework, you can make your own CMS from it. It basically depends on what exactly you want to achieve. – leymannx May 15 '20 at 15:28
  • Technically the core block layout is a display variant plugin. You can replace it with a different one like panels/page manager or you can even invent your own. – 4k4 May 15 '20 at 15:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.