Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Decoupled Blocks Powered by Paragraphs

Security covered Under active development

Part of the Decoupled ecosystem · 20 projects

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!

Ask your assistant about Decoupled Blocks Powered by Paragraphs

Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works

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 PHP Release date
1.0.0-alpha1 Pre-release 9–11 Feb 10, 2025
1.0.x-dev Dev 9–11 Feb 10, 2025