Release Day: Drupal 8 Render API

This week we're adding 10 more tutorials to our Drupal 8 Module Development Guide which dive into the Render API, an essential part of every module developer's toolkit. In fact, if you're writing custom code for Drupal and you want to display something on the screen you're going to have to use the Render API at some point.

If you've ever looked at the code in Drupal there's a good chance you've encountered the Render API -- even if you didn't know what you were looking at. It's an essential part of the process that Drupal uses to display content and create forms. Both module and theme developers are going to encounter and need to understand the Render API, at least at a high level.

Our suggestion: everyone writing code for Drupal, whether it's backend or front-end, should go through the first 2 tutorials in this list. Anyone needing to create or manipulate render arrays should keep going for more in-depth understanding of the Render API and how to use it.

Drupal 8 Render API tutorials:

In the coming weeks we'll be recording videos to go along with most of the tutorials listed above, as well as adding more Render API tutorials covering caching, creating custom render element types, and more examples of outputting common data structures as renderable arrays. Then, since the Render API is a fundamental part of the Drupal 8 Form API, astute readers probably already guessed that we're planning to cover that soon.

Do you want to know more about specific parts of the Render API? Let us know so we can add them to our pipeline.

Comments

These tutorials have been extremely helpful to me. Thank you. With respect to learning additional parts of the Render API, I'd love to see a good tutorial on "How to render layouts" with the layout plugin manager service. The documentation currently available at drupal.org was good enough to get me started, but I got stumped when trying to apply it to building a custom form. (I was able to place the form elements in regions in buildForm so that everything *looked* the way I wanted but then my form no longer functioned properly...)

Hey Lisa, I'm guessing you're talking about the new Layout API in Drupal core. Which, I haven't personally played with at all yet but am excited to dig into. The subsystem is currently in the experimental category and slated for a stable release with Drupal 8.5.x. We'll probably start to poke at it in the near future, but likely not release any finished content until after the stable version is released. I will however make sure that this suggestion gets added to our to-do list. Thanks!

I'm also curious to hear a bit more about what you're trying to accomplish with the Layout API. Again, not being all the familiar with it yet I'm interested in the use-cases that people are coming up with.

So, did you find any example or article how to attach needed layout style to custom form, rendered via buildForm function?

I'm not sure I understand the question. Are you asking about the Layout Builder tool in Drupal core? Or about attaching something like layout related CSS styles to a form?

If layout builder, I don't know the answer. I've still not really played with it much at all.

If CSS your best bet us creating asset library and then using the #attached property of the $form render array in your buildForm method to attach the library to the form.

Add new comment