Entity Blocks

Allows creating fieldable blocks that display any entity using configurable view modes.

entity_block
10,685 sites
38
drupal.org
Drupal 8 Drupal 9 Drupal 10 Drupal 11

Install

Drupal 11, 10 v2.0.0
composer require 'drupal/entity_block:^2.0'
Drupal 9, 8 v8.x-1.1
composer require 'drupal/entity_block:8.x-1.1'

Overview

Entity Blocks module enables site administrators to create blocks that reference and display any Drupal entity (nodes, users, taxonomy terms, etc.) using the entity's view modes. This provides a flexible way to place entity content in block regions without duplicating content or creating custom blocks manually.

The module creates a custom entity type called 'entity_block' which stores references to target entities. Each entity block can be configured to display a specific entity using a chosen view mode (such as teaser, full, or custom view modes). The blocks are fieldable, meaning you can attach additional fields to the entity blocks if needed.

This is particularly useful when you need to display the same content in multiple regions, showcase featured content in sidebars, or create reusable content blocks that automatically update when the source entity changes.

Features

  • Create blocks that display any Drupal entity (nodes, users, taxonomy terms, commerce products, etc.)
  • Select from available view modes to control how the entity is rendered in the block
  • Entity selection uses autocomplete for easy entity lookup by title
  • Blocks are automatically updated when the referenced entity changes
  • Entity blocks are fieldable - you can add custom fields to extend their functionality
  • Integrates with Drupal's standard block placement system for region assignment
  • Supports all entity types that have view modes defined
  • Automatic filtering of incompatible view modes (token, queue, rss)

Use Cases

Featured Content Sidebar

Display a featured article node in a sidebar block using the teaser view mode. When the featured article is updated, the block automatically reflects the changes. Create an entity block targeting the 'node' entity type with 'article' bundle and 'teaser' view mode, then select the specific article to feature.

Author Profile Block

Show a user profile in a block region. Create an entity block targeting 'user' entity type and select the author to display. Use a custom view mode like 'author_bio' to control exactly which user fields are shown.

Product Spotlight

For Commerce sites, display a specific product in promotional block regions. Target the 'commerce_product' entity type and select the product to spotlight, choosing an appropriate view mode for the promotional display.

Category Description Block

Display a taxonomy term description in block regions. Target 'taxonomy_term' entity type, select the vocabulary bundle, and choose a term to display its description and associated fields in a sidebar.

Reusable Content Snippets

Use a 'snippet' content type with various reusable text blocks. Create entity blocks referencing these snippet nodes to place the same content in multiple page regions without duplication.

Tips

  • Create dedicated view modes for block display to control exactly which fields appear in entity blocks without affecting other displays.
  • Use meaningful titles for entity blocks as they appear in the block administration interface.
  • Entity blocks are fieldable - consider adding fields like 'Background Color' or 'CSS Class' to provide additional styling options.
  • Remember that changes to the referenced entity are automatically reflected in the block - no need to update the entity block itself.
  • The module filters out 'token', 'queue', and 'rss' view modes as these are typically not suitable for block display.

Technical Details

Admin Pages 3
Entity blocks /admin/structure/entity-blocks

Main administrative page for managing entity blocks. Displays a table of all created entity blocks with their configuration details including ID, title, target entity type, bundle, view mode, and referenced entity ID. Provides links to edit each block.

Add entity block /admin/structure/entity-blocks/manage/add

Form to create a new entity block. Allows selecting the target entity type, bundle, view mode, and specific entity to display in the block.

Edit /admin/structure/entity-blocks/{entity_block_id}/edit

Form to edit an existing entity block. Same fields as the add form, pre-populated with the current configuration.

Permissions 1
Administer entity blocks

Allows users to create, edit, and delete entity blocks, as well as access the entity block administration pages.

Hooks 7
hook_entity_info

Defines the entity_block entity type with its properties, including fieldability, bundle configuration, and admin paths.

hook_block_info

Registers all entity blocks as Drupal blocks, using the entity block title as the block info.

hook_block_view

Renders the entity block by loading the target entity and displaying it using the configured view mode.

hook_permission

Defines the 'administer entity blocks' permission.

hook_menu

Defines admin menu paths for listing, adding, and editing entity blocks, plus autocomplete callback.

hook_field_extra_fields

Defines pseudo-fields for the entity_block entity type for display management.

hook_schema

Defines the database schema for the entity_block table.

Troubleshooting 4
Entity autocomplete is not working

Ensure the Entity Reference module is properly installed and enabled. The autocomplete functionality depends on Entity Reference's handler and autocomplete system.

Block not appearing after creation

After creating an entity block, you must assign it to a region. Go to Administration > Structure > Blocks and find your entity block in the list to assign it to a region.

Some entity types are not available

Entity types must have at least one valid view mode (other than token, queue, or rss) to appear in the entity type dropdown. Check that your entity type has view modes defined.

View mode not displaying as expected

Configure the view mode display settings for the target entity type at Administration > Structure > Content types > [Type] > Manage display (or equivalent for other entity types). Ensure fields are enabled for the selected view mode.

Security Notes 3
  • The 'administer entity blocks' permission grants full control over entity blocks. Assign this permission carefully as users can reference and display any entity they have access to.
  • Entity access checks are not performed when viewing entity blocks - any entity referenced by a block will be displayed regardless of the viewing user's permissions on that entity. Consider this when referencing sensitive content.
  • Note: There is a typo in hook_menu() where 'adminiter entity blocks' is used instead of 'administer entity blocks' for the list page access check, which may cause access issues.