Rendering Plugin Blocks the Right Way in Drupal with Views and Webform

Image by Freepik

Christian Sanders of ComputerMinds explores how to programmatically render plugin blocks in Drupal using the Block Plugin API. While Drupal supports content, config, and plugin blocks, this article zeroes in on plugin blocks—those typically defined in src/Plugin/Block and extending BlockBase.

Sanders shares his experience implementing multiple blocks—two Views blocks and one Webform block—by determining their $plugin_id values. For Views, block IDs must follow the format views_block:view_machine_name-view_display, a detail hidden in the plugin’s deriver logic. For Webform blocks, the ID is simply webform_block, but it requires passing a configuration array including the webform_id.

Once the block instance is created using createInstance(), developers can call build() to get the render array and then add configurations like block label, theme wrapper, and attributes. These render arrays can be assigned to variables and printed in templates.

  • Plugin ID pattern: views_block:view_id-display_id
  • Webform blocks require webform_id in config
  • Use createInstance() + build() to get render arrays
  • Watch out for missing hooks like hook_block_view()
  • Manual access checks and caching may be necessary
  • Use Drush or Twig Tweak for discovery and debugging

Read the full tutorial on Rendering Plugin Blocks the Right Way to see complete code examples and detailed explanations.

Disclosure: This content is produced with the assistance of AI.

Disclaimer: The opinions expressed in this story do not necessarily represent that of TheDropTimes. We regularly share third-party blog posts that feature Drupal in good faith. TDT recommends Reader's discretion while consuming such content, as the veracity/authenticity of the story depends on the blogger and their motives. 

Note: The vision of this web portal is to help promote news and stories around the Drupal community and promote and celebrate the people and organizations in the community. We strive to create and distribute our content based on these content policy. If you see any omission/variation on this please reach out to us at #thedroptimes channel on Drupal Slack and we will try to address the issue as best we can.

Related Organizations

Related People

Upcoming Events

Latest Opportunities