Adding weight and type=hidden will still show the field in entity forms

Created on 26 July 2021, almost 4 years ago
Updated 19 June 2025, 5 days ago

Problem/Motivation

When you create a custom entity and set a field to have type=hidden and with a weight display option, the field will be rendered in the entity form.

Steps to reproduce

Add the following field in the entity definition

    $fields['test_field'] = BaseFieldDefinition::create('string')
      ->setLabel(t('Test'))
      ->setSettings([
        'default_value' => '',
        'max_length' => 255,
        'min' => 0,
        'text_processing' => 0,
      ])
      ->setDisplayOptions('view', [
        'label' => 'above',
        'type' => 'string',
        'weight' => 5,
      ])
      ->setDisplayOptions('form', [
        'type' => 'hidden',
        'weight' => 5,
      ])
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayConfigurable('view', TRUE);

Proposed resolution

Entity type=hidden should not show the form field even if weight attribute is set.

🐛 Bug report
Status

Active

Version

11.0 🔥

Component

field system

Created by

🇺🇸United States anoopjohn Washington D. C.

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024