Incompatibility with Data field field type

Created on 17 April 2025, 28 days ago

Problem/Motivation

The module is incompatible with Data field .
When both modules are enabled, and upon visiting the settings form for Field Encryption, an error occurs due to the way the "Default properties" element is constructed.

\Drupal\field_encrypt\Form\SettingsForm::buildForm() calls BaseFieldDefinition::create($type) which in turn calls \Drupal\datafield\Plugin\Field\FieldType\DataFieldItem::propertyDefinitions().
DataFieldItem::propertyDefinitions() relies upon the "field_name" property being set in the definition array.

Steps to reproduce

  1. Install and enable both the Data field and Field Encryption modules
  2. Visit /admin/config/system/field-encrypt
  3. This results in a "Undefined array key "field_name""

Proposed resolution

I am not sure what the best way to deal with the problem would be. I don't know how much work would be needed to make Field Encryption work with the "data_field" field type, or if it would even be possible due to the dynamic nature of the properties on that field type.

Maybe add some "defensive code" to at least avoid this kind of error, and document this incompatibility somewhere ?

🐛 Bug report
Status

Active

Version

4.0

Component

Code

Created by

🇫🇷France arousseau

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

Comments & Activities

  • Issue created by @arousseau
  • 🇮🇳India Ishani Patel

    Hello,
    I've followed the steps and am facing the same issue.

  • 🇯🇵Japan ptmkenny

    Thanks for reporting this.

    The BaseFieldDefinition::create($type) is this one in SettingsForm.php?

          foreach ($field_types as $name => $field_type) {
            // Special handling for preconfigured definitions.
            // @see \Drupal\Core\Field\FieldTypePluginManager::getUiDefinitions()
            $type = str_starts_with($name, 'field_ui:') ? $field_type['id'] : $name;
            $field_definition = BaseFieldDefinition::create($type);

    We could probably follow the comment here and do something closer to what getUiDefinitions does in FieldTypePluginManager:

      /**
       * {@inheritdoc}
       */
      public function getUiDefinitions() {
        $definitions = $this->getDefinitions();
    
        // Filter out definitions that can not be configured in Field UI.
        $definitions = array_filter($definitions, function ($definition) {
          return empty($definition['no_ui']);
        });
    
        // Add preconfigured definitions.
        foreach ($definitions as $id => $definition) {
          if (is_subclass_of($definition['class'], '\Drupal\Core\Field\PreconfiguredFieldUiOptionsInterface')) {
            foreach ($this->getPreconfiguredOptions($definition['id']) as $key => $option) {
              $definitions["field_ui:$id:$key"] = array_intersect_key(
                $option,
                ['label' => 0, 'category' => 1, 'weight' => 1, 'description' => 0]
              ) + $definition;
            }
          }
        }
    
        return $definitions;
      }
    

    Also, I have documented that this module is not compatible with Data Field on the project page.

Production build 0.71.5 2024