When an entity is exported in a feature, it is being casted as an object which works fine for non-Entity classed entities (node etc), but can cause issue for Entity classed ones (field collections). During import entity_save is eventually called for the object, but since the object is not of the right class, the right save method is not called.

The following code is in place that does that conversion and according to the author the reason is entity_import will try to save the object to the DB immediately. https://www.drupal.org/node/1429604#comment-5566480

+      // Convert entities to array to avoid having them in JSON returned from standard implementation of $entity->export().
+      if (is_object($entity) && method_exists($entity, 'export')) {
+        $entity = get_object_vars($entity);
+      }

However that appears to be incorrect or at least out-dated now. entity_import does not try and save the entity and using entity_export & entity_import should be preferred over type casting all entities to stdClass.

Attached patch just removes that code so features_var_export can export the Entity object properly.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sarvab created an issue. See original summary.

Status: Needs review » Needs work

The last submitted patch, 2: uuid-entity-class-export-2776429-2.patch, failed testing.

The last submitted patch, 2: uuid-entity-class-export-2776429-2.patch, failed testing.

The last submitted patch, 2: uuid-entity-class-export-2776429-2.patch, failed testing.

The last submitted patch, 2: uuid-entity-class-export-2776429-2.patch, failed testing.

skwashd’s picture

@sarvab is this patch generated against current HEAD of the 7.x-1.x branch?

skwashd’s picture

Status: Needs work » Needs review

Let's see what the bot thinks of the change...