Problem/Motivation

So, in $entity object you will find $entity->original->original and so on in recursion.

Delete a translation put the $entity into recursion i.e. we're getting original many times in $entity object because we're not cloning the object.

php version - 5.6.25

Proposed resolution

Add the clone entity into $entity->original

Remaining tasks

Review the patch

User interface changes

None

API changes

None

Data model changes

None

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

naveenvalecha created an issue. See original summary.

nileshlohar’s picture

Title: Delete a translation put the entity_delete into recursion » On translation delete $entity object contains original in recursion
Issue summary: View changes
Status: Active » Needs review
FileSize
600 bytes

Here, is the patch.
Cloned $entity before assigning it to $entity->original

stefanos.petrakis@gmail.com’s picture

Status: Needs review » Needs work

Good morning and thanks for this report,

Although the patch is very simple to review (and most probably has no side-effects), the problem description needs a little more work so that it can be reviewed properly.
Could you please elaborate on the following points:

a) How does one reproduce this problem? Is it possible to reproduce it from the GUI? Or, programmatically?
b) How exactly is entity_delete involved?
c) What is the actual problem in the end? How does this recursive behaviour becomes evident? Is there a specific error reported?

Thanks for the help again

nileshlohar’s picture

Issue summary: View changes
Status: Needs work » Needs review

Good Morning and thanks for your time stefanos.petrakis !

Here are the answers to your questions:

a) How does one reproduce this problem? Is it possible to reproduce it from the GUI? Or, programmatically?

--> We got it while deleting the node translation as we had implemented hook_entity_presave()
which gets invoked from entity_translation_entity_save($entity_type, $entity);

In hook_entity_presave() implementation we were traversing through each element and it's sub-elements of $entity object so, we got error because of recusrion in $entity->original.

b) How exactly is entity_delete involved?

--> entity_delete() is not involved directly.
but, In entity_translation_delete_confirm_submit() , $entity->original is poiting to $entity object directly so it creating recursion.
and making issue while entity translation deletion.

c) What is the actual problem in the end? How does this recursive behaviour becomes evident? Is there a specific error reported?

--> We were getting PHP error of max_nesting_level has been reached.

The issue is poiting $entity->original again to its parent $entity which is creating recursion and the solution is to use "clone".

Hope this helps,
feel free to ask questions.

chadguitar’s picture

When calling "hook_entity_translation_delete($entity_type, $entity, $langcode)", I needed to access a field's original values. The problem is, in the function "entity_translation_delete_confirm_submit", the following line is problematic.

$entity->original = $entity;

Objects are assigned by reference, and therefore any change to $entity will also change $entity->original. Although this doesn't appear to break anything, I needed to access original field values to do some additional work. These field values were no longer present in $entity->original. It's a show stopper and blocks me from doing any useful work in "hook_entity_translation_delete".

The antidote to this problem would be the following:

$entity->original = clone $entity;

stefanos.petrakis@gmail.com’s picture