InvalidArgumentException: The entity object refers to a removed translation (es) and cannot be manipulated.

Created on 10 November 2023, about 1 year ago
Updated 19 September 2024, 3 months ago

Problem/Motivation

I have a translated website. When I delete a translated node, rabbit hole causes a fatal error.

InvalidArgumentException: The entity object refers to a removed translation (es) and cannot be manipulated.

The error happens in Form Manager Service with the call to getBehaviorPlugin which gets called on the deleted node.

  public function redirectToEntityEditForm(array $form, FormStateInterface $form_state) {
    $entity = $form_state->getFormObject()->getEntity();
    $plugin = $this->behaviorInvoker->getBehaviorPlugin($entity);

Steps to reproduce

1. Enable Translation
2. Add a second language
3. Enable translation on article
4. Translate the article
5. Enable Rabbithole
6. Configure rabbithole settings for the node.
7. Delete the translated node.

🐛 Bug report
Status

RTBC

Version

2.0

Component

Code

Created by

🇺🇸United States Greg Boggs Portland Oregon

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

Merge Requests

Comments & Activities

  • Issue created by @Greg Boggs
  • Status changed to Needs work about 1 year ago
  • 🇵🇱Poland ad0z

    It happens because module custom submit handler $form['actions']['submit']['#submit'][] = [$form_mangler, 'redirectToEntityEditForm']; is attached to entity delete form, this submit is executed after NodeDeleteForm submitForm so content translation does not exist anymore and it ends with exception when module tries to get translation field value here:

        $trigger_default_bundle_action =
          // Entity does not have Rabbit Hole field.
          !$entity->hasField(self::FIELD_NAME)
          // Entity has the field, but it's null (hasn't been set).
          || $entity->get(self::FIELD_NAME)->action == NULL
          // Entity has been explicitly set to use the default bundle action.
          || $entity->get(self::FIELD_NAME)->action == 'bundle_default';
    

    There is $disallowed_operations = ['delete', 'cancel', 'reset', 'layout_builder', 'replicate'];/code> list already in <code>rabbit_hole_form_alter, I suppose we do not have to attach module's submit handler when current_operation is in the list.

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.4 + Environment: PHP 8.1 & MariaDB 10.3.22
    last update about 1 year ago
    24 pass
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.2 & MySQL 8
    last update about 1 year ago
    24 pass
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update about 1 year ago
    24 pass
  • Status changed to Needs review about 1 year ago
  • Status changed to RTBC about 1 year ago
  • 🇩🇪Germany broon Potsdam

    I just ran into that error while trying to delete a translation. In the system, entity_language_fallback is enabled which eventually leads to more trouble. For example, with three languages set up (EN, FR, IT) and the language fallback for IT is FR instead of the default language EN, if you try to delete the IT translation the mentioned error appears.

    If the user does not read the error message and just reloads the page, the delete form submit will run again and delete the next language in the fallback chain.

    Adding the patch provided by ad0z in #2 fixes the error. From a functional perspective: RTBC.

  • 🇩🇪Germany akoe

    Also tested the patch with Rabbit Hole 2.0.0-alpha5 and Drupal 10.2.2 and can confirm it solves the exception thrown by ContentEntityBase->getTranslatedField()

  • 🇹🇷Turkey emircan erkul Turkey

    Tested, the error no longer appears but the page redirected to /delete route.

  • Status changed to Needs work 10 months ago
  • 🇹🇷Turkey emircan erkul Turkey

    Workaround prevents redirectToEntityEditForm function from running.

  • 🇧🇪Belgium andreasderijcke Antwerpen / Gent

    I'm raising this to 'major', as from my experience:

    If you reload the page and accept the resubmission of the delete action, because you think the deletion failed, all translations and thus the node will be deleted.
    This means content loss, and might even warrant 'critical'.

  • 🇵🇱Poland ad0z

    @Emircan Erkul

    Could you provide more information? Steps to reproduce it?
    When redirectToEntityEditForm function is not executed, default Drupal behaviour redirect browser based on "destination" query parameter or entity "collection" link(when destination is not provided) or default link template(when none of them is provided). That's kinda interesting how you got redirected to delete form then..

  • 🇧🇪Belgium mschudders

    I've tested the patch as well and cannnot reproduce the issue of Emircan Erkul.

    For me it seems to be working properly. Will test further to be sure.

  • 🇧🇪Belgium kriboogh

    Patch didn't apply to alpha5, updated it.

  • Status changed to RTBC 3 months ago
  • 🇸🇮Slovenia joco_sp

    I tried the #2 on the 2.0.0-alpha5 version and it works.

    As this is quite problematic if you refresh the page after you get the error, because it completely delete the node I agree with @andreasderijcke that this is a major issue. I am also changing the status back to RTBC.

  • Merge request !75Update file rabbit_hole.module → (Open) created by joco_sp
  • 🇸🇮Slovenia joco_sp

    I've used the #2 and created the merge request.

  • Pipeline finished with Failed
    3 months ago
    Total: 496s
    #280978
  • First commit to issue fork.
Production build 0.71.5 2024