Support bundle fields created in ContentEntityBase::baseFieldDefinitions()

Created on 30 January 2026, 5 days ago

Problem/Motivation

When creating bundle fields via ContentEntityBase::bundleFieldDefinitions() it's not possible to encrypt them. I suspect the Field Encryption module assumes all bundle field have been created via the Field UI and have thus have the getThirdPartySetting() method.

Steps to reproduce

1. Create a custom content entity.
2. Manually add the required Field Encryption basefield.

  public static function baseFieldDefinitions(EntityTypeInterface $entity_type): array {

    $fields = parent::baseFieldDefinitions($entity_type);

    // Add field encryption storage field. Needed for the Field Encrypt module.
    $fields[ProcessEntities::ENCRYPTED_FIELD_STORAGE_NAME] = StateManager::getEncryptedFieldStorageDefinition();

3. Create bundle field in ContentEntityBase::bundleFieldDefinitions() and set the

public static function bundleFieldDefinitions(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) {
    $fields = parent::bundleFieldDefinitions($entity_type, $bundle, $base_field_definitions);

    $fields['imap_password'] = BundleFieldDefinition::create('string')
      ->setName('imap_password')
      ->setTargetEntityTypeId($entity_type->id())
      ->setTargetBundle($bundle)
      ->setLabel(t('Password'))
      ->setRequired(TRUE)
      // Make the field encrypted.
      ->setSetting('field_encrypt.encrypt', TRUE)
      ->setSetting('field_encrypt.properties', ['value']);

Proposed resolution

Create a patch that changes the loading of field settings.

Remaining tasks

-

User interface changes

-

API changes

-

Data model changes

-

🐛 Bug report
Status

Active

Version

3.2

Component

Code

Created by

🇳🇱Netherlands Sander Wemagine

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