Remove "value" property definition from EntityFieldFetchItem

Created on 5 January 2024, 6 months ago

Problem/Motivation

The "value" property on the EntityFieldFetchItem field type is marked as being needed, but I saw this note on "\Drupal\Core\Field\FieldItemInterface" as guidance for implementing the "schema" method:

Computed fields having no schema should return an empty array.

I think it is worth a shot to try removing the value property since it has no functionality in that class.

Proposed resolution

1. Return an empty array in EntityFieldFetchItem::schema().
2. Remove the value property from EntityFieldFetchItem::propertyDefinitions().
3. Add an update hook that deletes the existing value column.

example code for #3:

$field_names = \Drupal::entityTypeManager()
                        ->getStorage('field_storage_config')
                        ->loadByProperties(['type' => 'entity_field_fetch']);

foreach ($field_names as $field_name) {
    $tables = [
        'node__' . $field_name, 
        'node_revision__' . $field_name
    ];

    foreach ($tables as $table) {
        if (Drupal::database()->schema()->fieldExists($table, $field_name . '_value')) {
            Drupal::database()->schema()->dropField($table, $field_name . '_value');
        }
    }
}

This might turn into more can-o-worms than it helps so maybe not worth the time. I tried to think of better ways to get rid of the value column in the update hook, but the way I proposed doesn't feel right...and I'm probably missing something that would cause errors.

πŸ“Œ Task
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States afinnarn

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

Comments & Activities

Production build 0.69.0 2024