Score:0

How do I get the type of a "Custom block" entity?

ve flag

I created two custom block types.

screenshot

How do I retrieve the type of custom block in hook_theme_suggestions_block_alter()?

function mytheme_theme_suggestions_block_alter(array &$suggestions, array $variables) {
  if (isset($variables['elements']['content']['#block_content'])) {
    // $variables['elements']['content']['#block_content']->getEntityTypeId() returns 'block_content'. 
  }
}
Score:2
cn flag
  if (isset($variables['elements']['content']['#block_content'])) {
    array_splice($suggestions, 1, 0, 'block__bundle__' . $variables['elements']['content']['#block_content']->bundle());
  }
Score:2
ru flag

Use the bundle() function

EntityInterface::bundle

This applies to every entity, no matter if node, user or custom content block

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.