# Field Visibility Conditions

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.

## Requirements

- Drupal 10.x or 11.x

## Installation

Install as you would normally install a contributed Drupal module. For further
information, see
[Installing Drupal Modules](https://www.drupal.org/docs/extending-drupal/installing-drupal-modules).

## Configuration

### Admin Settings

The module provides an administration page to control which conditions are
available for field visibility at:

Administration > Configuration > Content > Field Visibility Conditions

From this page, administrators with the 'administer field visibility conditions'
permission can select which conditions should be available when configuring
field visibility.

### Field Settings

When enabled, the module will add visibility settings automatically to all field
configuration forms, based on the conditions enabled in the admin settings.

## 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:

```php
/**
 * 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! Please feel free to submit a Pull Request.

## License

This module is licensed under the same terms as Drupal core.
