Score:0

How to access block contents in run within hook_form_alter?

fr flag

I am using Drupal 9 and I need to get the block content within hook_form_alter implementation, I tried these lines:

$bid = 'consumerorganizationselection';
$block = \Drupal::entityTypeManager()->getStorage('block')->load($bid);

but this ended up returning the block configuration not the content. enter image description here

Is there any approach to get that block content in Drupal 9?

I tried the solution of the duplicate question here: How to get a field value of custom block? but the uuid is returned for me is NULL:

$bid = 'consumerorganizationselection';
$block = \Drupal\block\Entity\Block::load($bid);
$uuid = $block->getPlugin()->getDerivativeId();

What can be the issue here?

4uk4 avatar
cn flag
Then the block probably doesn't contain block content but is rather a plugin generating the content in PHP. If you are trying to render the block see https://drupal.stackexchange.com/questions/171686/how-can-i-programmatically-display-a-block
I sit in a Tesla and translated this thread with Ai:

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.