0

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'. 
  }
}
0

2 Answers 2

2
  if (isset($variables['elements']['content']['#block_content'])) {
    array_splice($suggestions, 1, 0, 'block__bundle__' . $variables['elements']['content']['#block_content']->bundle());
  }
2

Use the bundle() function

EntityInterface::bundle

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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.