Drupal Blocks and Block Types

Design reusable Drupal block types with code-based definitions and concise machine names.

34|12|Updated Mar 10, 2019
One-click install
npx skills add https://github.com/theodorosploumis/drupal-best-practices --skill drupal-blocks-and-block-types
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Drupal Blocks and Block Types
Source: https://github.com/theodorosploumis/drupal-best-practices/tree/main/ai/skills/blocks
Command: npx skills add https://github.com/theodorosploumis/drupal-best-practices --skill drupal-blocks-and-block-types

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill helps you avoid the common pitfalls of unmanageable and inconsistent Drupal blocks. It ensures that custom blocks and block types are designed for reusability, portability, and easy maintenance across different environments.

Core Features & Use Cases

  • Reusable Block Types: Guide the creation of custom block types and plugins that are committed to code, rather than one-off content blocks tied to specific UUIDs.
  • Concise Naming: Get suggestions for machine names and admin labels that are short, human-readable, and avoid region-specific prefixes.
  • Node-Standard Field Plans: Apply content modeling best practices (like those for nodes and paragraphs) to block fields and view modes.
  • Use Case: When developing a "Call to Action" block, use this Skill to ensure it's created as a reusable block type with a generic machine name like cta, and its fields mirror your content type standards.

Quick Start

Outline a reusable testimonial custom block type with a concise machine name, fields, recommended view modes, and caching notes.

Frequently Asked Questions about Drupal Blocks and Block Types

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create reusable custom block types in Drupal instead of one-off content blocks?

Reusable custom block types are defined in code as plugins rather than stored as UUID-specific content blocks. This approach ensures portability across environments, consistent naming, and maintainability. Code-based definitions let you version control your block structure and redeploy it reliably.

What naming conventions should I use for Drupal block machine names?

Machine names for blocks should be concise and generic, avoiding region-specific prefixes or 'block_' prefixes. Use descriptive names like 'cta' or 'testimonial' that reflect the block's purpose and remain consistent across environments for easier deployment and reuse.

How should I structure fields and view modes for custom Drupal blocks?

Apply the same content modeling standards used for nodes and paragraphs to your block fields and view modes. Align field types, naming, and view mode configurations with your broader content architecture to maintain consistency and reduce cognitive overhead across your site.

What caching strategy should I apply to custom block types?

Document caching requirements for each block type based on its content freshness needs and reusability scope. Proper cache tags and contexts ensure blocks display current data while maximizing performance benefits across your site's environments.

Can I use content block plugins to build portable, environment-agnostic Drupal blocks?

Code-based block plugins are designed for portability across environments. UUID-specific content blocks are environment-dependent and difficult to redeploy, so block type plugins are the recommended approach for maintainable, reusable site architecture.