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.

Read-only Field Widget

4,822 sites Security covered
View on drupal.org

This module provides a read-only field widget for Drupal forms. It allows you to display a field's value in a view mode directly within the form, useful for adding context or displaying pre-filled information. You can select a specific formatter to control how the read-only value is displayed.

Provides a new field widget which shows a read-only (or view mode) version of a field on a form.

Useful for adding context while editing content.

Field widgets are rendered using one of the available field formatters for that field. The formatter can be selected in the field widget settings.

The widget is available to use for any field type.

NOTE: The field must have a value for this widget to show - this can either be a default value (set while the widget uses a form type widget or programatically) or from the saved value while on an entity edit form.

- Still shows up if the user doesn't have edit access to the field but they do have view access.
- The formatter options for the field are available under the widget settings.
- Label position and hide/show option is available under the widget settings.

A common scenario where this module is useful is switching the form widget type of an entity reference field conditionally when the referenced entity is known. This makes a prettier UX than a disabled select/autocomplete.

/**
 * Implements hook_ENTITY_TYPE_prepare_form().
 */
function my_module_node_prepare_form(\Drupal\Core\Entity\EntityInterface $entity, $operation, \Drupal\Core\Form\FormStateInterface $form_state) {

  // Set the value of field_my_entity_ref_field if id is known.
  if ($entity instanceof NodeInterface && $entity->bundle() == 'MY_BUNDLE') {
    $ref_id = \Drupal::request()->get('ref_id');
    $ref_node = \Drupal\node\Entity\Node::load($ref_id);
    if ($ref_node instanceof NodeInterface && $ref_node->bundle() == 'MY_REF_BUNDLE') {
      $entity->set('field_my_entity_ref_field', $ref_node);
    }
  }
}

/**
 * Implements hook_entity_form_display_alter().
 */
function my_module_entity_form_display_alter(\Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display, array $context) {

  // Change the field_my_entity_ref_field to a readonly field widget if id is known.
  if ($context['entity_type'] == 'node' && $context['bundle'] == 'MY_BUNDLE') {
    $ref_id = \Drupal::request()->get('ref_id');
    $ref_node = \Drupal\node\Entity\Node::load($ref_id);
    if ($ref_node instanceof NodeInterface && $ref_node->bundle() == 'MY_REF_BUNDLE') {
      $component = $form_display->getComponent('field_my_entity_ref_field');
      if ($component) {
        $component['type'] = 'readonly_field_widget';
        $component['settings'] = [
          'label' => 'inline',
          'formatter_type' => 'entity_reference_label',
          'formatter_settings' => [
            'entity_reference_label' => ['link' => FALSE],
          ]
        ];
        $form_display->setComponent('field_my_entity_ref_field', $component);
      }
    }
  }
}

Activity

Total releases
3
First release
Jul 2025
Latest release
11 months ago
Releases (12 mo)
3 ▲ from 0
Maintenance
Slowing

Release Timeline

Releases

Version Type Release date
2.1.0 Stable Aug 7, 2025
2.1.x-dev Dev Aug 7, 2025
2.x-dev Dev Jul 29, 2025