I created a module that has several pages of administration. One of these pages is a block creation page. When the block is created the name of the block is kept in the database. The block build() method will return a theme array where the twig file will use the variable to build the markup.
On another admin page there will be a place where the user attaches a block to a certain type of data. Along with that is the node ID(s) that this data can appear on.
I’ve gotten everything done except for how to send the data to the block if the current node is in the database and related to the block/data.
How is this done in Drupal 8|9? Is it preprocess?
And how do I send the data to the correct block for display?
This is how I envisioned it. Please correct me if I am wrong.
- Detect the NID in module (preprocess???)
- Query the database to see if any of the records contain the matching NID
- If there is a match, then find the matching data for the NID and save it to a variable
- Use the block name that is attached to that matching NID/Data set and send
the data to that block to be rendered.
This module is almost done. I just need to know how to accomplish this. Thanks.