Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment | File | Size | Author |
---|---|---|---|
#2 | entity_original-2847920-2.patch | 600 bytes | nileshlohar |
|
Comments
Comment #2
nileshlohar CreditAttribution: nileshlohar commentedHere, is the patch.
Cloned $entity before assigning it to $entity->original
Comment #3
stefanos.petrakis@gmail.comGood 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
Comment #4
nileshlohar CreditAttribution: nileshlohar commentedGood Morning and thanks for your time stefanos.petrakis !
Here are the answers to your questions:
--> 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.
--> 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.
--> 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.
Comment #5
chadguitar CreditAttribution: chadguitar as a volunteer commentedWhen 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;
Comment #6
stefanos.petrakis@gmail.com