Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: OpenID Connect / OAuth client 3.0.0-alpha9 New alpha version released for module openid_connect (3.0.0-alpha9). Release: Timelinr 1.0.1 Minor update available for module timelinr (1.0.1). Usage Milestone: Simplify Module simplify crossed 10,000 active installs. Usage Milestone: Views Reference Filter Module entityreference_filter crossed 10,000 active installs. Usage Milestone: Dropdown Language Module dropdown_language crossed 10,000 active installs. Usage Milestone: Paragraphs Browser Module paragraphs_browser crossed 10,000 active installs. Usage Milestone: OpenAPI Module openapi crossed 10,000 active installs. Usage Milestone: Decoupled Router Module decoupled_router crossed 10,000 active installs. Usage Milestone: Time Field for Drupal 8+ Module time_field crossed 10,000 active installs. Module Revived: Entityqueue Buttons 1.1.2 Module entityqueue_buttons updated after 8 months of inactivity (1.1.2).

Static Setting: Conditions

284 sites Security covered Drupal 10–11
View on drupal.org

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

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
3
Tracked since
Mar 2025
Latest release
1 year ago
Releases (12 mo)
0 ▼ from 3
Maintenance
Dormant

Release Timeline

Releases

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