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). Varbase Media Header 9.2.1 Minor update available for module varbase_media_header (9.2.1). 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 you to use the Static Settings API to create reusable contexts within your Drupal site. These contexts can then be used as conditions, for example, to control block visibility.

Leverage the Static Settings API to create Drupal contexts.

Description

The Static Setting Conditions module provides a way to utilize the Static Settings API to provide conditions in Drupal. It utilizes the API to create reusable contexts that can be applied throughout your Drupal site.

Requirements

- Drupal 10.x or 11.x
- PHP 8.1 or higher

Installation

1. Download the module:
You can download the module using Composer:

composer require drupal/static_setting_contexts

2. Enable the module:
After downloading, enable the module using Drush or the Drupal admin interface:

drush en static_setting_contexts

Or, enable it through the admin interface at /admin/modules.

Usage

Once the module is enabled, it will allow you to use any of the Static Settings you have defined as conditions.

Example

Create a custom Static Setting inside your module's src/Plugin/StaticSettings directory, and refer to the docs for Static Settings API
to understand how to use the settings. Below is an example setting.

<?php

declare(strict_types=1);

namespace Drupal\MYMODULE\Plugin\StaticSettings;

use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\static_setting_contexts\Attribute\StaticSettings;
use StaticSettings\BaseStaticSettingInterface;

/**
 * Enum class for custom static settings.
 */
#[StaticSettings(
  id: 'test_enum',
  label: new TranslatableMarkup('Test Enum'),
  description: new TranslatableMarkup('A test enum for the site.'),
)]
enum TestEnum: string implements BaseStaticSettingInterface {
  case OptionA = 'option_a';
  case OptionB = 'option_b';
  case OptionC = 'option_c';
}

Once you have created at least one setting condition forms (for example Block visibility) will display the available options as conditions.

Note

Due to the way that Drupal namespacing works, your settings will not be able to be validated by the Static Settings API unless you make
composer's autoloader aware of your settings. You can do this by adding the following to your composer.json file:

"autoload": {
  "psr-4": {
    "Drupal\\MYMODULE\\Plugin\\StaticSettings\\": "web/modules/custom/MYMODULE/src/Plugin/StaticSettings"
  }
}

Contributing

Contributions are welcome! If you would like to contribute to this module, please follow these steps:

1. Open an issue on the issue tracker
2. Create a Merge Request or add a patch
3. Mark your issue as Needs Review.

License

This module is licensed under the GPL-2.0+ license.

Maintainers

- Owen Bush

Activity

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

Release Timeline

Releases

Version Type Release date
1.0.2 Stable Apr 25, 2025
1.0.1 Stable Apr 11, 2025
1.0.0 Stable Mar 6, 2025