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: Opensolr Search 4.5.0 Minor update available for module opensolr_search (4.5.0). 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. Module Revived: Entityqueue Buttons 1.1.2 Module entityqueue_buttons updated after 8 months of inactivity (1.1.2).

Field Visibility Conditions

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

This module allows you to control the visibility of fields on your Drupal site based on configurable conditions. It's useful for multi-site setups where you want to share code but hide specific fields on certain sites by defining conditions that determine when a field should be displayed.

A Drupal module that allows you to control the visibility of fields based on configurable conditions.

Overview

Field Visibility Conditions provides a flexible way to control when fields are displayed or hidden on your Drupal site. This module extends Drupal's field configuration to include conditional visibility rules, making it easy to show or hide fields based on various conditions.

But why?

The benefit of this approach is for multi-sites, or shared codebase platforms, that share configuration across multiple sites but want some flexibility in control of what fields are present on entity forms. For example, if there are two sites sharing the same codebase, Site A and Site B, and only Site B needs a particular field on an entity type bundle, then using third party settings we are able to configure the visibility of that field based on a condition - this could be one provided by core, the contrib space, or something custom. This way both sites can still share the same configuration, as the third party settings are stored in config, but the conditions are evaluated per-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/field_visibility_conditions

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

drush en field_visibility_conditions

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

Configuration

The module offers a settings page to configure which conditions are available for use with restricting field visibility.

Usage

1. Navigate to the field configuration for any field where you want to set visibility conditions
2. Look for the "Field Visibility" section
3. Add one or more conditions that determine when the field should be visible
4. Configure the condition parameters as needed
5. Save the field configuration

Extending the module

Developers can alter the available conditions using the provided hook:

/**
 * Implements hook_field_visibility_conditions_available_conditions_alter().
 */
function my_module_field_visibility_conditions_available_conditions_alter(array &$conditions, FormStateInterface $form_state, ?string $form_id): void {
  // Remove specific conditions
  $conditions_to_remove = [
    'language',
    'request_path',
  ];
  $conditions = array_diff_key($conditions, array_flip($conditions_to_remove));
}

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

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
6
Tracked since
Mar 2025
Latest release
1 year ago
Releases (12 mo)
0 ▼ from 6
Maintenance
Dormant

Release Timeline

Releases

Version Type Core Release date
2.0.0 Stable 10–11 May 19, 2025
1.2.1 Stable 10–11 May 6, 2025
1.2.0 Stable 10–11 May 5, 2025
1.1.0 Stable 10–11 Apr 25, 2025
1.0.1 Stable 10–11 Mar 13, 2025
1.0.0 Stable 10–11 Mar 13, 2025