tool_layout_builder
Tool - Layout Builder provides Tool API plugins for working with Drupal Layout Builder programmatically. It is designed for systems that need to discover available building blocks and section layouts, create complete layouts, or edit existing layouts incrementally.
Features
This module provides 3 Tool plugins:
tool_layout_builder:get_layout_builder_blocks
Returns available inline block types, their field schemas, allowed values where available, and available section layouts. This is the discovery step used before building or editing a layout.tool_layout_builder:set_entity_layout
Sets a complete Layout Builder override on an entity. This replaces the entire layout and is intended for first-time page creation or full rebuilds.tool_layout_builder:edit_entity_layout
Applies incremental operations to an existing layout. Supported actions areadd_section,remove_section,add_block,update_block, andremove_block.
The module is intentionally entity-agnostic. It does not assume nodes, specific bundles, or project-specific block types.
Typical use cases:
- AI assistants that build or update Layout Builder pages
- external systems that need structured discovery of available block types
- custom automation that creates unpublished drafts or assembles landing pages
- incremental layout editing without manually rebuilding the whole page
The module also supports field structures from the custom_field module by passing values as arrays of row objects keyed by the custom field’s column names.
Post-Installation
This module does not add a user-facing configuration page.
After installation, it exposes Tool API plugins that can be used by compatible consumers such as AI/function-calling systems or custom integrations.
To use the module effectively:
- Enable Layout Builder on the target entity type/bundle.
- Ensure the entity stores Layout Builder overrides.
- Call
tool_layout_builder:get_layout_builder_blocksfirst to discover valid block types, field schemas, and section layouts. - Use
tool_layout_builder:set_entity_layoutto create a full layout, ortool_layout_builder:edit_entity_layoutto make incremental changes.
The write tools save Layout Builder override data directly to the entity.
Additional Requirements
- Drupal core with
layout_builder block_content- Tool
These are declared as module dependencies.
Recommended modules/libraries
layout_builder_browserif you want discovery to respect a curated allowlist of inline blockscustom_fieldif your block types use structured multi-column field data- AI/function-calling consumers that can invoke Tool API plugins
Similar projects
This module is not a Layout Builder UI enhancement. It does not provide a visual page builder interface for editors.
Instead, it focuses on a programmatic API surface via Tool API plugins. Its main differentiator is that it exposes Layout Builder discovery and write operations in a structured format suitable for automation, AI assistants, and external orchestration layers.
Supporting this Module
Issues, patches, and feedback are welcome.
Documentation
The module includes technical documentation in its README and API documentation in tool_layout_builder.api.php.
Extension points are available so site-specific modules can:
- alter discovered field metadata
- normalize or validate field values before inline blocks are saved
Two generic alter hooks are available:
hook_tool_layout_builder_field_info_alter()hook_tool_layout_builder_field_values_alter()
Notes and limitations
set_entity_layoutreplaces the entire layout.edit_entity_layoutupdates blocks by index, which is practical for automation but not intended as a stable external identifier scheme.- Field validation depends on discovered schema plus any installed alter hooks.
- Project-specific field semantics are intentionally out of scope and should be handled by extension modules.
🤖 Assisted Development
This module is maintained with the help of AI assistants for code generation, review, testing, and documentation. All code is carefully reviewed by the maintainers to ensure that quality and security standards are met.