Score:1

Sending data to custom block

gb flag

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.

mradcliffe avatar
cn flag
Hi, it's a little difficult for me to understand what you're asking. It helps to narrow down to a single question. I think the goal is providing an alternative to Drupal's native Block Layout administration interface with a custom Condition plugin that looks up its condition based on some additional saved data? I might focus the question by showing how you're currently calling / loading the block in the module.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.