Skip to content

JSON Configuration

shabib edited this page Nov 7, 2026 · 1 revision

JSON Configuration

Backdrop Theme Setup uses JSON configuration files to define optional setup operations for Backdrop CMS themes.

The goal is to let theme designers prepare sample content, taxonomy terms, menus, Views filters, and Layout settings without writing separate PHP import functions for every theme.

The PHP library handles the setup operations, while JSON files describe what should be configured.

Project status: Proof of concept. The JSON format and supported operations may change during development.

1. Configuration Directory

All setup files are stored inside the theme's settings-content directory.

backdrop_theme_setup/
├── backdrop_theme_setup.info
├── theme-settings.php
├── includes/
│   └── theme-setup.inc
└── settings-content/
    ├── taxonomy/
    │   └── terms.json
    ├── content/
    │   └── content.json
    ├── menu/
    │   └── links.json
    ├── views/
    │   └── filters.json
    ├── layouts/
    │   ├── settings.json
    │   └── blocks.json
    └── files/
        └── example.jpg

Each configuration file is associated with a specific setup operation.

Theme designers can customize these files according to their own theme requirements.

2. General JSON Rules

All configuration files must contain valid JSON.

Follow these basic rules:

  • Use double quotes for property names and string values.
  • Do not include trailing commas.
  • Do not add JavaScript-style comments.
  • Use UTF-8 encoding.
  • Use the machine names of existing Backdrop entities and fields.
  • Avoid hard-coded entity IDs when the library supports name-based references.

Example:

{
  "name": "Example",
  "enabled": true,
  "weight": 0
}

JSON does not support PHP expressions or executable code.

The setup library reads the files and performs supported operations using Backdrop APIs.

3. Taxonomy Configuration

File: settings-content/taxonomy/terms.json

This file defines taxonomy terms that should be created during setup.

Example

{
  "terms": [
    {
      "vocabulary": "tags",
      "name": "Web Development",
      "description": "Articles and resources about web development.",
      "path": "topics/web-development"
    },
    {
      "vocabulary": "tags",
      "name": "Design",
      "description": "Design resources and inspiration.",
      "path": "topics/design"
    }
  ]
}

Configuration fields

Property Description
vocabulary Existing vocabulary machine name
name Taxonomy term name
description Optional term description
path Optional URL alias

Important notes

  • The target vocabulary must already exist.
  • The library does not automatically create vocabularies.
  • Existing terms are checked to reduce duplicate imports.
  • Term IDs are generated by Backdrop.

Using term names instead of fixed IDs makes configurations more portable between installations.

4. Content Configuration

File: settings-content/content/content.json

This file defines sample nodes to import into the website.

Example

{
  "content": [
    {
      "type": "page",
      "title": "About Us",
      "body": {
        "value": "Welcome to our example website.",
        "format": "filtered_html"
      },
      "status": 1,
      "path": "about"
    },
    {
      "type": "post",
      "title": "Our First Article",
      "body": {
        "value": "This is an example article.",
        "format": "filtered_html"
      },
      "status": 1,
      "path": "articles/first-article"
    }
  ]
}

Common properties

Property Description
type Existing content type machine name
title Node title
body Body field content
status Publication status
path Requested URL alias

Requirements

Before importing content, verify that:

  1. The required content types exist.
  2. Referenced custom fields are configured.
  3. Required taxonomy terms have been imported.
  4. Referenced image and file assets are available.
  5. Text formats are valid for the site.

The current importer supports several common Backdrop field types.

The exact JSON structure for custom fields depends on their field types and the library's field preparation logic.

Existing content

The importer checks configured URL aliases to avoid recreating content that already uses those aliases.

It does not provide a full content synchronization or rollback system.

Do not treat this feature as a replacement for Backdrop Configuration Management or a content migration framework.

5. Image and File Imports

Directory: settings-content/files/

Sample images and documents can be included with the theme.

Example:

settings-content/
└── files/
    ├── example.jpg
    ├── profile.png
    └── brochure.pdf

The library provides a managed-file import helper:

theme_setup_import_file($theme, $relative_path, $scheme = 'public');

The helper resolves the source file inside the theme's sample files directory and imports it using Backdrop's managed file system.

For the example theme, the default destination is under:

public://theme-setup/backdrop_theme_setup/

Important notes

  • Referenced files must exist.
  • File paths must remain inside the permitted sample files directory.
  • Existing managed files at matching destination paths may be reused.
  • The destination scheme defaults to public.
  • Imported files should be attached to appropriate entity fields when needed.

The library does not automatically discover and attach every file in the directory.

6. Menu Configuration

File: settings-content/menu/links.json

This file defines menu links to create during setup.

Example

{
  "links": [
    {
      "menu_name": "main-menu",
      "title": "Home",
      "path": "<front>",
      "weight": 0
    },
    {
      "menu_name": "main-menu",
      "title": "About",
      "path": "about",
      "weight": 1
    },
    {
      "menu_name": "main-menu",
      "title": "Articles",
      "path": "articles",
      "weight": 2
    }
  ]
}

Configuration fields

Property Description
menu_name Existing menu machine name
title Menu link title
path Internal path or supported destination
weight Link ordering weight

The library also supports parent-child menu relationships.

Recommendations

  • Import content and taxonomy terms before links that depend on their paths.
  • Confirm that the target menu exists.
  • Use valid internal paths.
  • Check for existing links before importing.

Menu imports are intended to configure sample navigation, not to replace the site's complete menu management interface.

7. Views Filter Configuration

File: settings-content/views/filters.json

This file describes taxonomy filter updates for existing Views.

A common challenge when distributing sample content is that taxonomy term IDs differ between installations.

For example, the term "Projects" might have ID 3 on one website and ID 12 on another.

Hard-coding those IDs in exported Views configuration makes the setup less portable.

Backdrop Theme Setup addresses this by resolving taxonomy terms dynamically.

Conceptual example

The configuration identifies:

  • An existing View.
  • A display within that View.
  • A taxonomy filter.
  • A vocabulary.
  • A term name.

The library then:

  1. Loads the existing View.
  2. Finds the configured display and filter.
  3. Resolves the taxonomy term by name and vocabulary.
  4. Updates the filter with the actual term ID.
  5. Saves the changed configuration.
  6. Invalidates the relevant Views caches.

Requirements

  • Views must be enabled.
  • The target View must already exist.
  • The target display must exist.
  • The configured taxonomy filter must exist.
  • The referenced taxonomy term must exist.

Important: This feature updates existing Views. It does not create new Views.

For exact JSON property names, refer to the repository's settings-content/views/filters.json file.

8. Layout Settings Configuration

File: settings-content/layouts/settings.json

This file configures supported settings on existing Backdrop Layouts.

Supported operations include:

  • Changing a Layout template.
  • Updating page title display settings.
  • Updating supported page title configuration.

Typical use case

A theme designer might want:

  • The home page to use a particular Layout template.
  • The default Layout to use another template.
  • Page titles to be hidden or displayed differently.

These settings can be applied during theme setup rather than requiring users to configure every Layout manually.

Important notes

  • Target Layouts must already exist.
  • The requested Layout template must be available.
  • Changing a template can affect the placement of existing blocks.
  • Only supported settings are modified.

Review the configuration before applying it to an existing website.

For the exact JSON format, see settings-content/layouts/settings.json in the repository.

9. Layout Blocks Configuration

File: settings-content/layouts/blocks.json

This file controls supported block operations inside existing Layouts.

The library can:

  • Add blocks.
  • Remove matching blocks.
  • Move existing blocks.
  • Set block positions.
  • Apply supported block settings.

Typical use case

A theme designer may want the home page to contain:

  1. A personal introduction block.
  2. A featured projects block.
  3. A recent articles block.

Instead of asking users to place each block manually, the designer can define the desired configuration in JSON.

Processing behavior

The library processes supported block removals before additions.

It then saves changed Layouts and resets Layout caches when necessary.

Important considerations

  • The target Layout must exist.
  • Referenced block plugins must be available.
  • Target regions must exist in the selected Layout template.
  • Removing blocks by plugin identifier can affect multiple matching instances.
  • Repeated setup operations should be tested carefully.

For the exact JSON structure, refer to settings-content/layouts/blocks.json.

10. Image Style Cache Management

Unlike the other setup operations, image style flushing does not require a dedicated JSON configuration file.

Available image styles are loaded directly from Backdrop.

The library provides:

theme_setup_flush_image_styles($styles = NULL);

The function accepts:

  • A single image style name.
  • An array of image style names.
  • NULL to flush all available styles.

The example theme settings interface allows administrators to select individual image styles.

Example

theme_setup_flush_image_styles(array(
  'thumbnail',
  'medium',
));

This operation clears generated image derivatives for the selected styles.

It does not delete the original image files.

The setup library does not require a global backdrop_flush_all_caches() call for this operation.

Backdrop Configuration Management Integration

Backdrop Theme Setup is designed to work alongside Backdrop CMS's built-in Configuration Management (CMI) system, not replace it.

Theme developers can include supported Backdrop configuration files in their theme's config directory to provide the site structure required by their theme.

For example:

backdrop_theme_setup/
├── config/
│   ├── taxonomy.vocabulary.portfolio_main.json
│   ├── node.type.project.json
│   ├── field.field.field_image.json
│   ├── field.instance.node.project.field_image.json
│   └── views.view.home_project.json
├── settings-content/
│   ├── taxonomy/
│   │   └── terms.json
│   ├── content/
│   │   └── content.json
│   ├── views/
│   │   └── filters.json
│   └── layouts/
│       ├── settings.json
│       └── blocks.json

What belongs in the config directory?

Use Backdrop's native configuration system for supported configuration, such as:

  • Taxonomy vocabularies.
  • Content types.
  • Field definitions and field instances.
  • Views and their displays.
  • Other supported configuration objects.

These files must follow Backdrop's native configuration format and naming conventions.

What belongs in settings-content?

Use Backdrop Theme Setup for additional setup operations, such as:

  • Importing taxonomy terms into existing vocabularies.
  • Creating sample content and attaching files.
  • Adding menu links.
  • Updating Views taxonomy filters with dynamically resolved term IDs.
  • Applying settings to existing Layouts.
  • Configuring Layout blocks.

Why separate them?

The config directory provides the website's configuration structure, while settings-content provides sample data and additional setup operations.

For example, a theme developer can:

  1. Provide a taxonomy vocabulary through native configuration.
  2. Import sample terms into that vocabulary using Theme Setup.
  3. Provide a View through native configuration.
  4. Update the View's taxonomy filter using the actual term IDs.
  5. Import sample content and configure its presentation in Layouts.

This approach allows theme designers to reuse Backdrop's existing features instead of recreating configuration management functionality in PHP.

Important: Including configuration files in a theme does not mean Theme Setup imports those files itself. Their installation and availability depend on Backdrop's native configuration handling and the site's existing configuration. Theme Setup operations should only run after their required configuration is available.

Theme developers only need to include the configuration files required by their particular theme.

11. Recommended Configuration Order

When preparing a theme for distribution, use the following order:

Step Operation Reason
1 Prepare site configuration Ensure content types, fields, Views, and Layouts exist
2 Import taxonomy terms Make term references available
3 Import sample content Create nodes and attach files
4 Import menu links Connect navigation to content
5 Update Views filters Resolve actual taxonomy term IDs
6 Apply Layout settings Select templates and title behavior
7 Configure Layout blocks Place available blocks in their regions
8 Flush image styles Regenerate derivatives when needed

The theme settings interface allows operations to be selected independently.

Running them in a controlled order makes debugging easier.

12. Configuration vs. Content

Backdrop Theme Setup does not replace Backdrop's Configuration Management system.

Backdrop Configuration Management is responsible for configuration entities and settings such as:

  • Content types.
  • Field definitions.
  • Views.
  • Layout configuration.
  • Other module and site settings.

Backdrop Theme Setup focuses on optional setup operations, especially where a theme needs sample content or dynamic configuration adjustments.

The two approaches can complement each other.

For example:

  1. Backdrop configuration provides a View.
  2. Theme Setup imports taxonomy terms.
  3. Theme Setup resolves the terms' actual IDs.
  4. Theme Setup updates the existing View filter.
  5. Theme Setup configures the home page Layout.

This approach avoids depending on fixed taxonomy IDs across different installations.

13. Security and Validation

JSON configuration files are treated as input data, not executable code.

The library includes path validation for JSON loading and managed-file imports.

However, theme developers should still follow these precautions:

  • Review all configuration files before running setup operations.
  • Avoid referencing untrusted files.
  • Use valid internal paths.
  • Test imports on a fresh installation.
  • Back up existing sites before changing Layouts or content.
  • Do not assume every operation can be reversed automatically.

Further validation and error-handling improvements are welcome.

14. Extending the Library

Backdrop Theme Setup is intended to be reusable.

A theme developer can integrate the library into another theme and supply theme-specific JSON files.

The public helper functions use the theme_setup_ prefix, while the example theme uses the backdrop_theme_setup machine name.

This separation allows the library to evolve independently from the demonstration theme.

Potential future improvements include:

  • Stronger JSON schema validation.
  • Better import reports and error messages.
  • Additional field type support.
  • Improved idempotency and rollback handling.
  • Automated tests.
  • Additional integration with Backdrop Configuration Management.

These are possible directions, not features promised by the current implementation.

15. Feedback and Contributions

Backdrop Theme Setup is an experimental project intended to encourage discussion about reusable theme setup workflows.

Feedback from theme designers and Backdrop developers is welcome.

Repository: https://github.com/shabib-m/backdrop_theme_setup

Issues: https://github.com/shabib-m/backdrop_theme_setup/issues

Backdrop CMS: https://backdropcms.org/


This documentation describes the current proof-of-concept design. Always consult the implementation and example JSON files for the exact supported configuration structure.

Clone this wiki locally