Problem/Motivation

On the saveToDedicatedTables() in the SqlContentEntityStorage.php is not working properly with mapitem fields, the following code:

 foreach ($storage_definition
            ->getColumns() as $column => $attributes) {
            $column_name = $table_mapping
              ->getFieldColumnName($storage_definition, $column);

            // Serialize the value if specified in the column schema.
            $value = $item->{$column};
            if (!empty($attributes['serialize'])) {
              $value = serialize($value);
            }
            $record[$column_name] = SqlContentEntityStorageSchema::castValue($attributes, $value);
          }

At the $value = $item->{$column}; is trying to get $item->value that does not exist in this item(the correct in my analysis would be $item->values)

Steps to reproduce

Programatically insert an array in a MapField, try to save the entity that has the field data.

Proposed resolution

I changed the code to:


            if(!isset($item->$column)){
              $value = $item->getValue();
            }
            else{
              $value = $item->$column;
            }

But its a invasive solution that changes the drupal core, and i want to discuss with you guys if this is really an issue and if this change is safe to do.

Remaining tasks

Discuss the problem and check if this is a core issue or it's a mistake from my part.
discuss if the proposed solution is ok.

Comments

thiagomoraesp created an issue. See original summary.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.