Drupal is a registered trademark of Dries Buytaert
Protected Pages 3.0.0 Major update available for module protected_pages (3.0.0). Commerce Core 3.3.8 Minor update available for module commerce (3.3.8). Search API HTML Element Filter 1.0.7 Minor update available for module search_api_html_element_filter (1.0.7). Layout Builder Reorder 2.0.1 Minor update available for module layout_builder_reorder (2.0.1). Ban 1.1.0 Minor update available for module ban (1.1.0). Field Formatter Range 2.0.0 Major update available for module field_formatter_range (2.0.0). Field Formatter Range 8.x-1.8 Minor update available for module field_formatter_range (8.x-1.8). UI Patterns (SDC in Drupal UI) 2.0.18 Minor update available for module ui_patterns (2.0.18). Search API Solr 4.3.11 Module search_api_solr updated after 14 months of inactivity (4.3.11). Provus Mega Menu Module provus_mega_menu crossed 1,000 active installs.

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!

Activity

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

Releases

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