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).

Read-only Field Widget

5,077 sites Security covered Drupal 10–11
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);
      }
    }
  }
}

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
4
Tracked since
Jul 2025
Latest release
3 weeks ago
Releases (12 mo)
1 ▼ from 3
Maintenance
Active

Release Timeline

Releases

Version Type Core Release date
2.1.1 Stable 10–11 Aug 9, 2026
2.1.0 Stable 8–11 Aug 7, 2025
2.1.x-dev Dev 10–11 Aug 7, 2025
2.x-dev Dev 8–11 Jul 29, 2025