Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: OpenID Connect / OAuth client 3.0.0-alpha9 New alpha version released for module openid_connect (3.0.0-alpha9). Release: Timelinr 1.0.1 Minor update available for module timelinr (1.0.1). Usage Milestone: Simplify Module simplify crossed 10,000 active installs. Usage Milestone: Views Reference Filter Module entityreference_filter crossed 10,000 active installs. Usage Milestone: Dropdown Language Module dropdown_language crossed 10,000 active installs. Usage Milestone: Paragraphs Browser Module paragraphs_browser crossed 10,000 active installs. Usage Milestone: OpenAPI Module openapi crossed 10,000 active installs. Usage Milestone: Decoupled Router Module decoupled_router crossed 10,000 active installs. Usage Milestone: Time Field for Drupal 8+ Module time_field crossed 10,000 active installs. Module Revived: Entityqueue Buttons 1.1.2 Module entityqueue_buttons updated after 8 months of inactivity (1.1.2).

This module allows frontend applications to fetch and display structured block content from a Drupal site, enhanced with paragraph entities for greater customization. It provides an API endpoint to retrieve blocks by path, enabling developers using frameworks like React and Next.js to easily integrate Drupal content.

The Decoupled Blocks Powered by Paragraphs module enables frontend applications to fetch and display blocks from a Drupal site's active theme. Blocks are enhanced with injected paragraph entities, making them highly customizable and structured for headless or decoupled projects.

This module is ideal for developers working with frameworks like React and Next.js who want a clean and consistent way to retrieve and render block content.

Features

  • Exposes Theme Blocks: Provides access to active theme blocks injected with paragraph entities for structured content delivery.
  • API-Driven: Retrieve blocks for any page using the simple endpoint: /api/decoupled/_blocks?path=/given-path
  • Customizable Field Exposure: Use the provided hook to control which paragraph fields and relationships are exposed through JSON:API specifications.

Post-Installation

Configuration Steps:

1. Enable the module via the Admin UI or Drush: drush en decoupled_blocks_paragraphs

Fetch blocks for a specific path using: /api/decoupled/_blocks?path=/your-path

Specify Your Custom Paragraph Field Name:

Implement the following hook to define the paragraph field name to be exposed

By default, the module uses field_paragraphs to retrieve data from the injected block.

/**
 * Alter paragraph field name.
 */
function hook_decoupled_blocks_paragraph_field_name(&$paragraphField) {
   $paragraphField = "field_paragraphs_name";
}

Customizing Exposed Paragraph Data:

Implement the following hook to define which fields should be exposed in the API response:

/**
 * Alter the paragraph fields exposed by the Decoupled Blocks API.
 *
 * @param string $paragraphType
 *   The type of paragraph to filter.
 * @param array &$filters
 *   The array of filters to apply to the JSON:API response.
 */
function hook_decoupled_blocks_filters_alter($paragraphType, &$filters) {
  if ($paragraphType === "custom-paragraph-type") {
      $filters = [
        "fields" => [
          "block_content--template_block" => "block_machine_name",
          "media--image" => "name,thumbnail",
          "file--image" => "filename,uri",
        ],
        "include" => "field_logo,field_logo.thumbnail",
      ];
  }
}
The injected paragraph field in blocks must be singular

Let me know if you'd like further tweaks!

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
2
Tracked since
Feb 2025
Latest release
1 year ago
Releases (12 mo)
0 ▼ from 2
Maintenance
Dormant

Releases

Version Type Core Release date
1.0.0-alpha1 Pre-release 9–11 Feb 10, 2025
1.0.x-dev Dev 9–11 Feb 10, 2025